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.

Return only the columns you need, such as A, B, D.
Example: B = 'East' or B contains 'Widget'. The builder combines this with the date filter using AND.
Choose how the QUERY date column should compare to the selected date.
Use an ISO date such as 2026-01-01 or a date cell such as F1.
Use an ISO date such as 2026-01-01 or a date cell such as F1.
Use the next day or next month with the Before (<) boundary for safer ranges.

Formula is valid and ready to copy.

Google Sheets formula
=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 syntax note
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 selected columns
=QUERY(A1:D100, "SELECT A, B, D", 1)

Use SELECT when the report should return only some source columns.

QUERY with text WHERE
=QUERY(A1:D100, "SELECT A, B, D WHERE B = 'East'", 1)

Use a normal WHERE condition when the matching value is fixed.

QUERY contains text
=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 with ORDER BY
=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 date range from cells
=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 date from another sheet cell
=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 GROUP BY total
=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 FORMAT date output
=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 with IMPORTRANGE and Col notation
=QUERY(IMPORTRANGE($H$1,"Sales!A:D"),"SELECT Col1, Col4 WHERE Col2 = 'East'",1)

Use Col1 notation when QUERY reads an imported array.

QUERY text condition plus optional date filter
=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 from another sheet tab
=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 numeric condition
=QUERY(A1:D100, "SELECT A, B, D WHERE D >= 300", 1)

Use number conditions without quotes.

Sample data

DateRegionProductAmount
2026-01-04EastWidget420
2026-01-12WestWidget310
2026-02-03EastGadget275
2026-02-15EastWidget640

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.

Cell date in a QUERY builder pattern
=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.

GROUP BY total with label
=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.

A1 letters vs Col1 notation

Use A, B, C, and D when the QUERY source is a normal A1 range such as A1:D100.

Use Col1, Col2, and Col3 when the source is an imported or generated array, including many IMPORTRANGE formulas.

QUERY with another sheet or IMPORTRANGE

For another sheet tab in the same file, point QUERY at a sheet-qualified range such as Sales!A1:D100.

For IMPORTRANGE, authorize the import first, then write the QUERY using Col1-style references because the imported result is an array.

IMPORTRANGE with Col notation
=QUERY(IMPORTRANGE($H$1,"Sales!A:D"),"SELECT Col1, Col4 WHERE Col2 = 'East'",1)

H1 should contain the source spreadsheet URL or key.

Common QUERY errors and fixes

Most QUERY errors come from quote handling, wrong column notation, invalid date literals, missing GROUP BY columns, or a header-row count that does not match the source.

Use the troubleshooting table below when a generated formula parses but returns blank rows or a QUERY error.

When not to use QUERY

Do not use QUERY when FILTER is shorter and the output should keep every source column in the same order.

Do not use QUERY in Excel workbooks. Excel does not support the Google Sheets QUERY function.

Sample results from the default data

Generated patternReturned result from the sample rowsUse when
SELECT A, B, DReturns the Date, Region, and Amount columns for all four sample rows.You need a report view without changing the source table.
WHERE B = 'East'Returns the three East rows: 2026-01-04, 2026-02-03, and 2026-02-15.You need one regional or status filter.
January date rangeReturns the two January rows and excludes the February rows.You need a month or date-window report.
GROUP BY B with SUM(D)Returns East = 1335 and West = 310 from the sample Amount column.You need a summary table instead of the original rows.

Troubleshooting

ProblemLikely causeFix
QUERY returns the wrong columnsThe SELECT clause uses column letters that do not match the source range.Update selected columns after changing the source range.
QUERY text condition failsText values inside the query string are missing single quotes.Use WHERE B = 'East' or WHERE C contains 'Widget'.
QUERY date filter returns no rowsThe formula uses a display date such as 1/1/2026 instead of a QUERY date literal.Use date 'YYYY-MM-DD' or TEXT(date_cell,"yyyy-mm-dd") inside the query string.
QUERY shows Invalid date literal for a date cellA cell reference such as F1 or Sheet2!C6 was placed inside date quotes, or the date serial was concatenated directly.Use date '"&TEXT(F1,"yyyy-mm-dd")&"' or date '"&TEXT(Sheet2!C6,"yyyy-mm-dd")&"' so QUERY receives yyyy-mm-dd text.
QUERY sort does not workORDER BY references a column that is not present in the source range.Use a real source column letter in ORDER BY, such as ORDER BY A DESC.
QUERY header row is treated as dataThe header-row argument is set too low or omitted.Use 1 when the first row contains column headers.
QUERY with IMPORTRANGE failsQUERY must use Col1, Col2 notation when the source is an imported array.Use Col1-style references or query the imported range after it is authorized.
QUERY GROUP BY returns an errorNon-aggregated selected columns are missing from GROUP BY.Add every non-aggregated selected column to the GROUP BY clause.
QUERY date range misses timestamp rowsThe end boundary uses <= instead of an exclusive next-day or next-month boundary.Use A < date 'next-boundary' for timestamp-safe ranges.

Common mistakes

  • Using double quotes inside the query string without escaping them.
  • Writing dates as plain text instead of date literals.
  • Mixing column letters and header names in the same query.
  • Changing the source range without updating selected column letters in SELECT, WHERE, or ORDER BY.

Related formulas

FAQ

How do I build a QUERY formula in Google Sheets?

Choose the source range, select the columns to return, add an optional WHERE condition or date filter, add ORDER BY if needed, then copy the generated =QUERY() formula.

Should I use A, B, C or Col1, Col2 in QUERY?

Use A, B, and C for normal A1 ranges. Use Col1, Col2, and Col3 when QUERY reads an imported or generated array such as IMPORTRANGE.

How do I add a date range to QUERY?

Add two WHERE conditions with date literals, such as A >= date '2026-01-01' and A < date '2026-02-01'. For date cells, concatenate TEXT(F1,"yyyy-mm-dd").

Can QUERY group, sort, and label results in one formula?

Yes. QUERY can use GROUP BY, ORDER BY, and LABEL in the same query string when the selected columns and aggregations are valid.

Does QUERY work in Excel?

No. QUERY is a Google Sheets function. Use FILTER, SORT, or Power Query patterns for Excel workbooks.

Why does QUERY need careful quote handling?

The query is a text string inside a formula, so text criteria and escaped quotes must be written correctly.

Is this Google Sheets QUERY builder free?

Yes. The builder is free, runs entirely in your browser, and never asks for an account or sign-in.

Do I need to download or install anything?

No. There is nothing to download or install. Set your options, then copy the generated =QUERY() formula straight into your sheet.

Is there a QUERY builder for Excel?

QUERY is a Google Sheets function, so it does not run in Excel. For Excel, use the SUMIFS, FILTER, or INDEX MATCH builders, or Power Query, to get similar report-style results.

Are these formulas generated with AI?

No. The builder uses deterministic TypeScript functions in the browser and does not call any AI API.

Do I need to upload my spreadsheet?

No. Enter ranges and criteria manually. The site does not upload, store, or process spreadsheet files.

Can I copy the generated formula?

Yes. Each output includes a copy button so you can paste the formula into Excel or Google Sheets.