Changing order in GroupBy and then sorting?

Is there an easier way to change the ordering and sorting in a GroupBy node?

I have a table where I wanted to group and sort by two different columns. Unfortunately, the first column I want to group / sort by is the last column in my data set, so when I use the GroupBy node it is always on the bottom. KNIME sorts by the earlier column first which I want it to be sorted on later.

Basically what I am looking for is to recreate a SQL query that is something like

Select, sum(a), b, c
group by c, b

(Sorry if that makes less sense, my SQL is rusty)

The only way I can see to do this in KNIME is to either use the Column Re-sorter node before I use the GroupBy node, or to us it afterwards and then also use the Sorter node to get the rows in the correct order.

Is there any easier way to do this? It seems awfully clunky when it would be much easier to simply be able to change the order of the columns in the GroupBy node and not have to use any other nodes.

Hi @ewhulbert,

Actually there is a solution to do that. You can pass the column names as flow variables and change the inclusion order of the columns. But I think using the Sorter node is a more straightforward approach.

Here is an example:


change_groupby_order.knwf (294.3 KB)



Appreciate the help. I agree, using the sorter / column re-sorter seems more straightforward so I will stick with that.

I hope they add the ability to re-order the grouping columns right in the GroupBy node. That seems like it would go a long way to making the workflows more straightforward and easy to use.


Hi there @ewhulbert,

just to catch up on this one - there already exists a feature request for this and I have added +1 for it.



Awesome, thanks for following up. I hope they can add it, would improve and simplify.


1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.