9

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)
user10012
  • 647
  • 1
  • 8
  • 23

2 Answers2

14

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

Ed Nelson
  • 10,015
  • 2
  • 27
  • 29
0

You have multiple problems in the query. First, remove the second occurence of LABEL. Secondly the order of columns H and G in the data table (and the query string) should be reversed. The aggregator (coulmn on which you group by) should be on the left.

rehan
  • 327
  • 4
  • 3