How to create a new column and group by that column in a selection?