Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Sheets - Query Multiple Columns With Custom Labels

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)
like image 513
user10012 Avatar asked Oct 24 '17 14:10

user10012


People also ask

How do I label a column in Google Sheets QUERY?

You can use the label clause in a Google Sheets query to create specific labels for the results of certain columns. In this example, we select all columns in the range A1:C13 and we label column A as 'Column A' in the resulting output.

How do I combine two columns in Google Sheets QUERY?

When you want to concatenate two columns use the ArrayFormula with Concat as below. Actually, the function CONCAT in Google Sheets is 'equal' to the Ampersand sign usage.


1 Answers

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

like image 104
Ed Nelson Avatar answered Oct 14 '22 01:10

Ed Nelson