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.

  • 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
  • 1
    This was super helpful. I was managed to produce nice graphs with very little effort from Google Forms data with this and the answer here webapps.stackexchange.com/a/146778/29110 – Mikko Ohtamaa Oct 12 '20 at 14:29

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")

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.