QUERY Function in Google Sheets: Syntax, Examples & Compatibility
Learn how to filter and summarize a data table with Google Visualization query language in Google Sheets. Includes grouping, explicit headers, sorted limits, mixed-type checks and portability notes.
Verification status: See the evidence and test scope described in this guide. How formula examples are checked
Quick answer: filter and summarize a data table with Google Visualization query language in Google Sheets. The reproducible examples below use explicit values so the formula’s meaning is testable without a large workbook.
Evidence: The function name and syntax are documented in the linked vendor function reference. Expected outputs were independently reasoned or checked outside the application. These are not native Google Sheets test results. A guide being published here does not certify every software release or file-import scenario.
Availability and version history
- Introduced: Introduction version not established by the official history reviewed.
- Availability: Documented in the rolling Google Sheets service; examples use the web spreadsheet workflow.
- Checked: October 14, 2026; official QUERY reference. Documentation check, not a new native test; existing example-verification notes retain their scope.
Syntax and arguments
=QUERY(data, query, [headers])
datasupplies the source cells.querycan be quoted text or a reference to a cell containing that text. Google documents both column-letter andColnotation; the examples below use letters for the stated worksheet range.Itemis a label, not the column identifierA.headerscounts input header rows. Omission or-1asks Sheets to guess. Use1for this example; an unheaded input needs0. Explicit counts make a report less dependent on inference.
Google’s QUERY reference documents these arguments. The query language resembles SQL but is a subset: do not add a SQL FROM clause; the first Sheets argument already supplies the input.
Best use case: Filter and summarize a data table with Google Visualization query language.
Set up the example sheet
Enter this sample range in A1:C5. Set A1 to Item, B1 to Team, and C1 to Amount; rows 2–5 hold the four records below:
| Item | Team | Amount |
|---|---|---|
| Pen | East | 10 |
| Pad | West | 20 |
| Box | East | 30 |
| Pen | East | 5 |
Enter the formula in an unused cell. For a formula returning several values, leave an unobstructed area where those values can expand. These formulas use comma argument separators in a typical English-language locale; commas or semicolons inside quoted text are data, not argument separators. Adapt the separator if your regional settings require it.
Worked example 1: QUERY with known input
=QUERY(A1:C5,"select A,C where B = 'East'",1)
Expected output: a 4-row by 2-column result, including the returned header row:
| Item | Amount |
|---|---|
| Pen | 10 |
| Box | 30 |
| Pen | 5 |
The headings shown are actual output cells. The final argument 1 identifies one input header row; it does not request removal of output labels.
The condition keeps only East team rows, and the select clause returns item and amount.
Worked example 2: a second QUERY case
=QUERY(A1:C5,"select A,C where C > 15",1)
Expected output: a 3-row by 2-column result, including the header:
| Item | Amount |
|---|---|
| Pad | 20 |
| Box | 30 |
The numeric condition selects only amounts above 15.
Compare both results before replacing literal values or short sample ranges with your own workbook data. For a spilling formula, compare every output cell, not only the top-left result.
Group a report and control its labels
Use the same A1:C5 data:
=QUERY(A1:C5,"select B,sum(C) group by B order by sum(C) desc label B 'Team',sum(C) 'Total'",1)
The complete 3-row by 2-column result is:
| Team | Total |
|---|---|
| East | 45 |
| West | 20 |
East contributes 10+30+5=45; West contributes 20. The totals sum to 65, matching all four input amounts. group by B combines team records, order by ranks the totals, and label makes the output headings explicit. In a grouped query, each selected column must be grouped or aggregated. Adding bare A to this selection would not identify which item belongs to a team’s combined row.
Take the largest records, then paginate
=QUERY(A1:C5,"select A,C where C > 0 order by C desc limit 2",1)
The complete output is Item | Amount, then Box | 30 and Pad | 20: three rows including the header. For the next overlapping window:
=QUERY(A1:C5,"select A,C where C > 0 order by C desc limit 2 offset 1",1)
This returns Item | Amount, then Pad | 20 and Pen | 10. The offset skips the first sorted data record before the limit is applied. Specify meaningful additional sort keys when tied amounts need a reproducible business order; this dataset has no tied amounts. See the query-language clause reference for clause order.
To maintain a query separately, put the text select A,C where C > 15 in G1, without surrounding quotation marks, and enter =QUERY(A1:C5,G1,1) elsewhere. Its complete result matches worked example 2.
Diagnose mixed column types
For query purposes, a column’s majority type determines its type; minority types become null. In a separate copy of the sample, replace C5’s 5 with the text pending. Three numeric amounts remain, so that text is treated as null:
=QUERY(A1:C5,"select A,C where C is not null",1)
The complete 4-row by 2-column result is Item | Amount, Pen | 10, Pad | 20, and Box | 30. The word has not been converted to zero, and the source cell has not been erased. Use is null or is not null for query null checks. Equal type counts and arbitrary error-valued input are outside these controls. Restore C5 to 5 before rerunning the earlier examples.
Practical advice and troubleshooting
When this formula helps: Use QUERY when you want a compact filtering and grouping pipeline. Use FILTER instead for direct Boolean conditions and formula-based criteria.
Important edge case: A query string has its own quoting rules: text conditions need single quotes inside the double-quoted Sheets formula string. Column identifiers, text values and returned headings have different roles; keep them separate.
If the result differs, first verify the text-versus-number types of the input cells, the argument separators for your locale, and the range size. For dynamic arrays, inspect occupied cells in the output area. In an imported workbook, confirm that the formula is being evaluated in Google Sheets and that quoted query text survived the conversion. Google Sheets is a rolling web service, so desktop release advice is not the appropriate availability check here.
Compatibility and version considerations
Excel does not have a native QUERY worksheet function with this signature; Power Query and FILTER/SORT functions solve different parts of the problem.
Google Sheets is a rolling cloud service; confirm the spreadsheet locale and leave the complete output area clear.
Function availability and parameter behavior must be judged for the specific application and release; a function documented in one spreadsheet does not automatically work in another.
Related guides and official documentation
-
Google Sheets QUERY reference — headers, syntax and mixed-column types.
-
Google Visualization Query Language — selected-column labels and query clauses.
Editorial verification: Direct QUERY help and query-language documentation reviewed October 14, 2026. All complete outputs, grouped totals and sorted windows were independently calculated from the supplied data; no native application run, screenshot, or version-specific output is claimed. Review the editorial testing standards if you require stronger proof before importing a workbook.