Google Sheets - Query Multiple Columns With Custom Labels

user10012 picture user10012 · Oct 24, 2017 · Viewed 14.8k times · Source

I am trying to create a simple query in my Google Sheet that will allow me to label the two columns it is outputting and sort the results based off of another column. However as soon as I add the Order By or the second Label command it throws and error. Here is my formula. Thanks for any help.

=query(A1:H,"SELECT H, SUM(G) WHERE H > '' AND G > 0 GROUP BY H ORDER BY A LABEL SUM(G) 'Sub Total', LABEL H 'Group Description'",0)

Answer

Ed Nelson picture Ed Nelson · Oct 24, 2017

Try this. You can hide the query return of column A if you need to. Also note the label syntax.

=query(A2:H,"SELECT A,H, sum(G) where H is not null and G>0 group by A,H order by A asc label sum(G) 'Sub Total', H 'Group Description',A 'Col A'",1)  

Here is my test spreadsheet:https://docs.google.com/spreadsheets/d/1U6OFD_bxkNu27WMFPYHcxps1SA3oH9m3jMTEdb-fiQY/edit?usp=sharing