Skip to content

QUERY LABEL and SELECT aliases fail when Col1 is mixed with column A

Updated

QUERY renames a column with the label clause, not with SQL AS. The name you label has to be the same name you selected. On a sheet range that name is A or sum(B). On an array (IMPORTRANGE, {A1:C10}) that name is Col1 or sum(Col2). label A 'sku' against Col1, or select Col1 as sku, is a parse error or NO_COLUMN. The data can be fine.

select A on an import, with no label at all, is Col1 vs A. This page is the label and the fake alias, including a query that already says Col1 in select and still says A in label. Keep the Google Sheets UI in English.

  1. Open a blank spreadsheet. In A1 type sku, B1 qty. A2 101, B2 2. A3 102, B3 5. A4 101, B4 4. Headers in row 1. The third argument of QUERY will be 1.

Label on a real sheet range. In D1 enter =QUERY(A1:B4,"select A, sum(B) group by A label A 'sku', sum(B) 'units'",1). The spill headers are sku and units, then the grouped rows. 101 totals 6. That block is the control. label names the expressions in select, and those expressions use column letters because A1:B4 is a sheet range.

SQL AS is not a label. In D6 enter =QUERY(A1:B4,"select A as sku, sum(B) as units group by A",1). The cell shows #VALUE!. The tooltip is Unable to parse query string for Function QUERY parameter 2. as is not how this language aliases a column. Leave D6 broken.

D6 selected. Formula bar shows a QUERY with select A as sku. D6 is #VALUE!. Tooltip: Unable to parse query string for Function QUERY parameter 2. D1 still spills sku and units from a label clause.

Array columns are Col1. In F1 enter =QUERY({A1:B4},"select A label A 'sku'",1). The { } makes an array. The cell shows #VALUE! or #N/A, and the tooltip mentions NO_COLUMN: A or unable to parse. Leave F1 broken. In F4 enter =QUERY({A1:B4},"select Col1 label A 'sku'",1). select is correct and label still says A. That is still NO_COLUMN or a label that does not match the selected expression. Leave F4 broken.

Label the Col name you selected. In F7 enter =QUERY({A1:B4},"select Col1, sum(Col2) group by Col1 label Col1 'sku', sum(Col2) 'units'",1). The spill matches D1’s headers and totals. Col1 is the sku column of the array even though it was column A on the sheet. This cell is the array control.

A label that does not match the aggregate. In H1 enter =QUERY(A1:B4,"select A, sum(B) group by A label sum(B) 'units'",1). This one works: sum(B) is exactly the selected expression. In H6 enter =QUERY(A1:B4,"select A, sum(B) group by A label B 'units'",1). B was not selected. sum(B) was. Leave H6 as the broken label. Copy the select expression into the label clause unchanged.

If { is #ERROR! Formula parse error, the array separator for your locale is not a comma. See array literal locale. That parse error is not NO_COLUMN.

Leave D6, F1, and F4 broken. Leave D1 and F7 as the labeled spills.

  • There is no AS in this query language. Renames go in label, after group by / pivot / order by, and each label is expression 'text' or expression "text" with a space between the expression and the quoted header. D6 put the rename in select. The parser stops.
  • Sheet ranges use letters. Arrays use Col1, Col2, counting from the left of the array. IMPORTRANGE is an array. {A1:B4} is an array. A query that was written for A1:B4 cannot be pasted around an array by changing only select A to select Col1 while label A stays. F4 is that half-edit.
  • The label expression must match the select expression. sum(B) and B are not the same token. sum(Col2) and Col2 are not the same token. Copy them.
  • NO_COLUMN: A on an array is the same family as Col1 vs A and QUERY parse string. This page is the case where select is already Col1 and the label (or an as alias) puts A back.
  • Headers in the output are text. They do not create a named range called sku. The next formula should read the spill, not the label string, unless you meant a header.

This is not QUERY with no rows. See QUERY no matching rows. D1 returns rows. D6 never ran the aggregation.

Leave D6 and F4 broken.

Sheet range: letters in both clauses. Keep D1. Add another rename by appending , A 'item' only if A is in the select. Do not write as.

Array: Col in both clauses. Keep F7: label Col1 'sku', sum(Col2) 'units'. When the source is IMPORTRANGE, use the same Col names you selected. See Col1 vs A for the import that has no label yet.

F7 selected. Formula bar shows QUERY of an array with select Col1, sum(Col2) group by Col1 label Col1 'sku', sum(Col2) 'units'. The spill header is sku and units. F4 is still an error because label still says A.

Do not wrap D6 in IFERROR. You would hide a syntax error and look like an empty report. See IFERROR vs IFNA.

If the tooltip says unable to parse and the query contains as, delete as and use label. If the tooltip says NO_COLUMN: A and the data is inside { } or IMPORTRANGE, change every A / B in select and label to Col1 / Col2. One clause is not enough.