I want to group and sort a particular data set. I've prepared the data using a QUERY function and using other functions.

Can I order by sum?

This is an example file I created: order by sum


The best result would be to use the QUERYfunction:

=SORT(QUERY(Data!A1:B6;"select A, sum(B), count(B) group by A");2;FALSE)

Since the sum already has been sorted ascendingly, the FALSE statement in the formula will sort descending using column 2.

| improve this answer | |
  • If the query includes a header row, the header gets sorted as well. How would this be used with a header row? – hughes Sep 7 '19 at 20:29
  • 1
    @hughes The third optional parameter of the QUERY function allows you to indicate a header. If omitted, Google will do that for you and leave the headers un-touched. – Jacob Jan Tuinstra Sep 9 '19 at 6:44

Another way is from within the query:

=QUERY(Data!A1:B6;"select A, sum(B), count(B) group by A order by sum(B) desc")
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.