QUERY() Function Errors in Google Sheets โ Complete Fix
A tiny SQL dialect living inside one text string โ powerful, but strict about its own internal syntax rules.
Table of Contents
- 1. A Query Language Inside a Formula Argument
- 2. Interactive Demo: Column Reference Translator
- 3. Cause 1: Using Worksheet Column Letters Instead of Col#
- 4. Cause 2: Double Quotes Instead of Single Quotes
- 5. Cause 3: Header Row Misdetection
- 6. Cause 4: Date Literal Formatting
- 7. QUERY Combined With IMPORTRANGE
- 8. Frequently Asked Questions
1. A Query Language Inside a Formula Argument
QUERY is unusual among spreadsheet functions because its second argument isn't standard formula syntax at all โ it's a small SQL-inspired query language, entirely self-contained within a text string. This dual-syntax nature (normal Sheets formula syntax on the outside, SQL-like syntax on the inside) is exactly why QUERY errors often trace back to confusing the rules of one syntax layer with the other.
2. Interactive Demo: Column Reference Translator
See exactly how your range's actual worksheet columns map to QUERY's internal Col# numbering.
3. Cause 1: Using Worksheet Column Letters Instead of Col#
The single most common QUERY mistake. Within the QUERY formula string, columns are always referenced as Col1, Col2, Col3, and so on, based on their position within your specified range โ never the worksheet's actual column letters like A, B, or C:
=QUERY(C2:F100, "SELECT C WHERE F='Completed'") โ Error - C and F are not valid within QUERY's own syntax
=QUERY(C2:F100, "SELECT Col1 WHERE Col4='Completed'") โ Correct - Col1 maps to worksheet column C, Col4 maps to worksheet column F
4. Cause 2: Double Quotes Instead of Single Quotes
Since the entire query string is itself wrapped in double quotes as a normal Sheets text argument, any text literal criteria within that string must use single quotes instead, to avoid prematurely closing the outer string:
=QUERY(A1:D100, "SELECT A WHERE B = "East"") โ Error - the inner double quotes break the outer string boundary
=QUERY(A1:D100, "SELECT A WHERE B = 'East'") โ Correct - single quotes for the inner text literal
5. Cause 3: Header Row Misdetection
QUERY attempts to automatically detect how many header rows your range contains, but this detection can misfire, especially with numeric-looking headers, merged header cells, or an unusual number of blank leading rows. This produces unexpected results (like your actual header text appearing as a data row, or the first real data row being silently excluded as if it were a header) rather than a clear, obvious error message.
Fix: Explicitly specify the header row count as QUERY's third argument rather than relying on automatic detection:
=QUERY(A1:D100, "SELECT A, B WHERE C > 100", 1)
Here, the 1 explicitly tells QUERY that exactly one header row exists at the top of the range, removing any ambiguity.
6. Cause 4: Date Literal Formatting
Comparing a date column within QUERY's criteria requires a specific literal date syntax, distinct from how you'd normally type a date elsewhere in Sheets:
=QUERY(A1:D100, "SELECT A WHERE C > 9/1/2026") โ Error - not valid QUERY date syntax
=QUERY(A1:D100, "SELECT A WHERE C > date '2026-09-01'") โ Correct - QUERY's specific date literal format (ISO-style, single-quoted)
7. QUERY Combined With IMPORTRANGE
As covered in our IMPORTRANGE guide, QUERY is frequently layered on top of IMPORTRANGE to filter cross-file imported data in a single step. When troubleshooting an error in this combined pattern, isolate each function separately first โ confirm IMPORTRANGE alone successfully returns raw data before adding the QUERY wrapper, so you know definitively which of the two functions is actually producing the error you're seeing.
8. Frequently Asked Questions
Why does QUERY use column letters like Col1 instead of A?
QUERY's SQL-like syntax refers to columns relative to your specified range, not the worksheet's actual column letters. The first column of your range is always Col1, the second is Col2, and so on, regardless of what worksheet column those cells physically occupy.
Why does QUERY return an error about a header row?
This happens when QUERY misjudges how many header rows exist in your range, especially with inconsistent or numeric-looking header text. Add the header parameter explicitly as the third argument to specify the exact number of header rows, rather than relying on QUERY's automatic detection.
Why do text criteria need single quotes inside QUERY's formula string?
QUERY's second argument is a text string containing SQL-like syntax, and within that string, text literals must be wrapped in single quotes, not double quotes, since double quotes are reserved for the outer formula string boundary itself.
Related Guides
Editorial Disclaimer: This guide is developed to the best of our domain knowledge and tested against Excel 2019+, Microsoft 365, and Google Sheets. Content is updated continuously as spreadsheet calculation engines evolve.