I am new in DDD and my understansing of the repository pattern is that it acts like a collection of aggregate roots where you can add, delete, update,etc a certain aggregate root. My question is, where code that performs aggregate functions (count, group by, sum, etc), should be placed, since it does not return or operate over an aggregate root? Thanks
Probably on another aggregate
The fact that you have a need to count certain aggregates indicates that you might be missing a level in your domain model. For example, if you have a 'customer' aggregate root but find yourself having to display the total number of customers, you need some notion in your domain to put that count on. You never just 'count' customers, instead your company has a list of customers and you can count the amount of customers in that list.
That being said, you need to ask yourself the question if the added complexity of introducing another aggregate is worth it. If you only need the number of customers it might be more realistic to simply put the count on your repository. If you find yourself needing a number of counts (get the total number of customers in a pie chart that makes a distinction between customers in your town, in your state, in your country, in your continent and 'other') if might be better to introduce a natural concept in your domain.