Haeminway haemin/way
한국어
5 min read

Google Sheets QUERY cheat sheet: 8 strings I reuse, 4 traps that return nothing

Filter, sort, total per customer, mini pivot and date ranges with QUERY. Every formula ran in a real Google Sheet, including the ones that fail quietly.

A glass funnel turning scattered tiles into one short ordered row above a sheet grid

Paid orders grouped by customer; unpaid rows are excluded

Sample order rows show five Paid values highlighted and three Unpaid values dimmed; grouped Paid totals are Leo 9, Mina 37.9, and Sara 27.5.View full-size diagram
Visual guideThese are the article's sample rows and QUERY result. The three Unpaid rows are excluded before the Paid amounts are grouped by customer.
Takeaway

QUERY is one formula that filters, sorts, totals and pivots. The catch: when you get the query string slightly wrong, it often returns an empty table instead of an error. Learn the four quiet traps below and it’s the most useful function in Sheets.

I ran every formula here in a scratch Google Sheet on 2026-10-15. The results are what Sheets actually returned.

The QUERY cheat sheet: the clauses select, where, group by, pivot, order by, limit, label must come in this order

The test data

A tab called Orders, headers in row 1:

RowA: DateB: CustomerC: ItemD: QtyE: TotalF: Status
22026-10-01MinaNotebook313.5Paid
32026-10-02LeoPen (blue)1012Unpaid
42026-10-03MinaStapler19.9Paid
52026-10-05SaraDesk lamp127.5Paid
62026-10-06LeoNotebook29Paid
72026-10-07SaraPen (blue)56Unpaid
82026-10-08MinaMarker set214.5Paid
92026-10-09JunNotebookTBD4.5Unpaid

Yes, TBD in the Qty column is on purpose. Someone always types that.

The shape of every QUERY

=QUERY(A1:F9, "select B, E where F = 'Paid'", 1)

Three parts: the range, the query string, and how many header rows (1). Inside the string you refer to columns by letter, and text values go in single quotes.

The clauses have a fixed order: select, where, group by, pivot, order by, limit, label (that’s the order in the cover image up top). I put order by before where to check, and got #VALUE! with a PARSE_ERROR. At least that one is loud.

Eight strings I actually reuse

Eight QUERY strings with the results they returned

JobQuery stringWhat I got
Filter rowsselect B, E where F = 'Paid'5 rows: Mina 13.5, Mina 9.9, Sara 27.5, Leo 9, Mina 14.5
Top 3select C, E order by E desc limit 3Desk lamp 27.5, Marker set 14.5, Notebook 13.5
Total per customerselect B, sum(E) where F = 'Paid' group by BLeo 9, Mina 37.9, Sara 27.5
Nicer headeradd label sum(E) 'Paid total'header became Paid total
Since a dateselect A, B, E where A >= date '2026-10-05'5 rows, Oct 5 to Oct 9
Text searchselect A, C where C contains 'Pen'the two Pen (blue) rows
Mini pivotselect B, sum(E) group by B pivot Fone column per status: Leo 9 / 12
One numberselect count(A) where F = 'Unpaid' label count(A) ''just 3, no header

That last one is my favourite. label count(A) '' deletes the header, so the cell holds a single number you can use in other formulas.

The pivot one is a pivot table that updates itself. Mina has no unpaid orders, so her Unpaid cell came back blank, not 0.

Using a cell as the filter

Put Mina in H1, then glue it into the string:

=QUERY(A1:F9, "select B, C, E where B = '"&H1&"'", 1)

That returned Mina’s three orders. The quotes are '" before and "' after: a single quote for QUERY, a double quote to end the Sheets string. Ugly, but it works.

Four traps that fail quietly

1. Dates from a cell need date and TEXT()

Gluing a date cell as text returns 0 rows; date plus TEXT returns 5 rows

H2 holds 2026-10-05.

"select A, E where A >= '"&H2&"'"                              → header only
"select A, E where A >= date '"&TEXT(H2,"yyyy-mm-dd")&"'"      → 5 rows

The first one compares a date column with a text string, so no error and no rows. Copy the second one.

2. Text values are case-sensitive

Two quiet traps: lowercase 'paid' returns only the header, and TBD in a number column comes back blank

where F = 'paid' (lowercase) returned only the header. The data says Paid. If people type statuses by hand, give the column a dropdown so it’s always spelled the same.

3. A mixed column drops the odd values

select C, D where C = 'Notebook' returned 3, 2, and an empty cell for Jun’s TBD.

QUERY decides each column’s type from the majority of its values. Qty is mostly numbers, so the text TBD became blank.

The row stayed, the value vanished. Keep one type per column. If you need “unknown”, leave it empty.

4. Forgot the quotes

where F = Paid gave #VALUE! with NO_COLUMN: Paid. Without quotes, QUERY thinks Paid is a column name. Easy to spot, at least.

Bonus: Col1, Col2 when the range is in braces

If you wrap the range in {} (for example to stack two tabs), letters stop working and you use Col numbers:

=QUERY({A1:F9}, "select Col2, Col5 where Col6 = 'Unpaid'", 1)

That gave Leo 12, Sara 6, Jun 4.5.

Copy-paste summary

You wantWrite
Filterwhere F = 'Paid'
Sort + top Norder by E desc limit 3
Totals per groupselect B, sum(E) group by B
Rename headerlabel sum(E) 'Paid total'
Date range from a cellwhere A >= date '"&TEXT(H2,"yyyy-mm-dd")&"'
Partial textwhere C contains 'Pen'
Single numberlabel count(A) ''
Ranges in {}Col1, Col2… instead of letters

When a QUERY suddenly shows only the header, check in this order: case, date format, quotes, mixed types. In my sheet that covered every empty result.

QUERY formulas that sometimes go blank? Send me what it does, and I’ll tell you whether it’s a formula fix or time for a small script.