3

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

1

2 Answers 2

7

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

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.

3
  • If the query includes a header row, the header gets sorted as well. How would this be used with a header row?
    – hughes
    Commented Sep 7, 2019 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
    Commented Sep 9, 2019 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 Commented Oct 12, 2020 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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