What QUERY Does
QUERY lets you ask a question of a range of cells in a short text command, a bit like a database query. Google documents the syntax as QUERY(data, query, [headers]). The data argument is the range to query, the query is written in the Google Visualization API Query Language and must be in quotation marks (or be a reference to a cell containing the text), and headers is an optional count of header rows at the top of data.
Google also notes that each column in data can hold only boolean, numeric (including date and time) or string values. If a column mixes types, the majority type decides, and the minority values are treated as null. For bank data that means amounts and dates should each be consistently typed.
The Sample Data
The data sits in A1:C9, with the header row Date, Category, Amount. The merchants and amounts are invented, and the category column is one you add yourself:
Date Category Amount
2026-09-02 Groceries 42.10
2026-09-03 Transport 18.50
2026-09-05 Groceries 27.90
2026-09-07 Entertainment 24.00
2026-09-09 Transport 18.50
2026-09-12 Groceries 63.25
2026-09-15 Entertainment 11.99
2026-09-18 Groceries 15.75Filter Rows with where
The query language reference documents the clause order as select, where, group by, pivot, order by, limit, offset, label, format and options, with every clause optional. Comparison operators include =, !=, <> and >, and string matching is case-sensitive. To list only the Groceries rows:
=QUERY(A1:C9, "select A, C where B = 'Groceries'", 1)The final 1 tells QUERY that the data has one header row. The result lists four rows with amounts 42.10, 27.90, 63.25 and 15.75. Because string matching is case-sensitive, a row labelled groceries would not match.
Total per Category with group by
The reference says group by creates one row per distinct combination of grouped values, and that each column in the select clause must either appear in the group by clause or be wrapped in an aggregation function. The documented aggregations are avg, count, max, min and sum.
=QUERY(A1:C9, "select B, sum(C) group by B", 1)On the sample data this returns three rows: Groceries 149.00 (42.10 + 27.90 + 63.25 + 15.75), Transport 37.00 and Entertainment 35.99. Together they come to 221.99, the same as adding all eight amounts.
You can combine clauses, keeping to the documented order. This version keeps only amounts above 20, totals them per category and sorts the largest first:
=QUERY(A1:C9, "select B, sum(C) where C > 20 group by B order by sum(C) desc label sum(C) 'Total'", 1)The rows above 20 are 42.10, 27.90 and 63.25 for Groceries (133.25) and 24.00 for Entertainment. Transport has no row above 20, so it does not appear. The expected output is Groceries 133.25, then Entertainment 24.00. Because aggregations are not allowed in the where clause, the filter is on the raw column C. Try the order by and label parts on your own sheet, since the pages consulted show them in separate simple examples.
Per Google, the query can also be a reference to a cell containing the text, for example QUERY(A2:E6,F2,FALSE) in its own sample usage. Keeping the query text in a cell makes it easier to edit without retyping the formula.
Getting the Data Into the Sheet
QUERY needs transactions already laid out in rows and columns. If yours are in a PDF statement, PDFtoRow converts bank statement PDFs to Excel or CSV and offers a free preview of the first 10 rows.
Convert Bank Statement PDFs Cleanly with PDFtoRow
Tired of fixing broken columns, corrupted dates, and numbers stored as text? PDFtoRow extracts transaction tables directly from digital PDF vector layers, preserving check numbers and outputting true numeric amounts. Statements up to 5 pages are free once per email every 24 hours. Check the 10-row preview before you download.
Frequently Asked Questions
QUERY(data, query, [headers]). The query is written in the Google Visualization API Query Language and must be in quotation marks or be a reference to a cell containing the text.
Google states that the majority type sets the column type, and the minority values are treated as null.
No. The query language reference says aggregation functions cannot appear in where, group by, pivot, limit, offset or options clauses.
Primary Evidence & Official References
- QUERY function - Google Docs Editors Help — support.google.com (Verified 2026-10-29). Official source documentation →
- Query Language Reference - Google Charts — developers.google.com (Verified 2026-10-29). Official source documentation →