Google Sheets formula builder
Google Sheets Query Builder
Build a copy-ready =QUERY() formula for Google Sheets using selected columns, WHERE conditions, sorting, headers, and optional date filters. Start with a simple range, add the logic you need, and copy a formula that uses valid QUERY syntax, including date literals and cell-based date references. No spreadsheet upload, no sign-in, and no AI prompt required.
Builder inputs
Use Google Visualization query syntax for WHERE and ORDER BY clauses.
=QUERY(A1:D100, "SELECT A, B, D WHERE A >= date '2026-01-01' AND A < date '2026-02-01' ORDER BY A DESC", 1)QUERY uses a quoted query string. Escape quotes carefully, use column letters for A1 ranges, and use date literals only when you add a date filter.How this formula works
- QUERY wraps a SQL-like query string inside a spreadsheet formula.
- Selected columns must be written as column letters when the source range uses A1 notation.
- WHERE conditions can use text, number, contains, and optional date filters.
- ORDER BY sorts the generated report without changing the source table.
Best fit
Best for
- Google Sheets reports that need selected columns, filtering, sorting, and optional date conditions in one formula.
- Reusable views where the output should include only specific columns.
- Small reporting formulas where the source table has a header row and stable column letters.
Not for
- Excel workbooks. QUERY is a Google Sheets function, not an Excel function.
- Very simple row filters where FILTER is easier to read and maintain.
- Data with mixed types in the same column unless you have cleaned the source first.
Useful formula variations
=QUERY(A1:D100, "SELECT A, B, D", 1)Use SELECT when the report should return only some source columns.
=QUERY(A1:D100, "SELECT A, B, D WHERE B = 'East'", 1)Use a normal WHERE condition when the matching value is fixed.
=QUERY(A1:D100, "SELECT A, B, D WHERE C contains 'Widget'", 1)Use contains when the matching text may appear inside a longer cell value.
=QUERY(A1:D100, "SELECT A, B, D WHERE B = 'East' ORDER BY D DESC", 1)Use ORDER BY when the report should sort returned rows.
=QUERY(A1:D100, "SELECT A, B, D WHERE A >= date '"&TEXT(F1,"yyyy-mm-dd")&"' AND A < date '"&TEXT(G1,"yyyy-mm-dd")&"'", 1)Use the date fields only when the report needs a date boundary.
=QUERY(Sales!A1:D100, "SELECT A, B, D WHERE A = date '"&TEXT(Settings!F1,"yyyy-mm-dd")&"'", 1)Use TEXT around date cells, even when the date lives on another sheet tab.
=QUERY(A1:D100, "SELECT B, SUM(D) GROUP BY B LABEL SUM(D) 'Total'", 1)Use GROUP BY when you want a summary table instead of matching source rows.
=QUERY(A1:D100, "SELECT A, B, D WHERE A >= date '2026-01-01' FORMAT A 'yyyy-mm-dd'", 1)Use FORMAT to control returned date display after filtering.
=QUERY(IMPORTRANGE($H$1,"Sales!A:D"),"SELECT Col1, Col4 WHERE Col2 = 'East'",1)Use Col1 notation when QUERY reads an imported array.
=QUERY(A1:D100, "SELECT A, B, D WHERE B = 'East' AND A >= date '2026-01-01' AND A < date '2026-02-01'", 1)Combine normal WHERE conditions with date filters using AND.
=QUERY(Sales!A1:D100, "SELECT A, B, D WHERE B = 'East' ORDER BY A", 1)Use a sheet-qualified range when the source table lives on another tab.
=QUERY(A1:D100, "SELECT A, B, D WHERE D >= 300", 1)Use number conditions without quotes.
Sample data
| Date | Region | Product | Amount |
|---|---|---|---|
| 2026-01-04 | East | Widget | 420 |
| 2026-01-12 | West | Widget | 310 |
| 2026-02-03 | East | Gadget | 275 |
| 2026-02-15 | East | Widget | 640 |
When to use this Google Sheets Query Builder
Use this builder when you know the source range and want a valid QUERY formula without writing every SELECT, WHERE, ORDER BY, and header argument by hand.
It is most useful for report-shaped output: selected columns, filtered rows, optional date ranges, and sorted results.
Build common QUERY patterns
Start with selected columns, then add a WHERE condition when the report should keep only one region, product, status, or text match.
The generated examples show plain SELECT, text WHERE, contains, ORDER BY, date range, GROUP BY, FORMAT, and IMPORTRANGE patterns.
Date cells and invalid date literals
If a QUERY formula says Invalid date literal, check whether the date cell was typed inside the quoted query string.
Write date '"&TEXT(F1,"yyyy-mm-dd")&"' instead of date 'F1' so the spreadsheet cell is converted before QUERY parses the date.
=QUERY(A1:D100, "SELECT A, B, D WHERE A >= date '"&TEXT(F1,"yyyy-mm-dd")&"'", 1)This fixes the common serial-number or cell-reference date literal error.
Advanced QUERY clauses
QUERY can group, aggregate, sort, and label output in one formula. GROUP BY is useful for summary totals, while FORMAT changes how returned dates display.
When you add aggregation such as SUM(D), every non-aggregated selected column must appear in the GROUP BY clause.
=QUERY(A1:D100, "SELECT B, SUM(D) GROUP BY B LABEL SUM(D) 'Total'", 1)B is grouped and D is summed for each region.
Detailed guide
Need the assumptions, examples, and troubleshooting?
The calculator stays focused here. The supporting reference has moved to its own page.
Read the Google Sheets Query Builder guide