Fix group by a function