Skip to main content

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.