Google Sheets QUERY Formula Generator

QUERY can filter, total and sort a table with a single formula, but its query string has its own rules: text in single quotes, dates with the word date, values from a cell joined with &, and Col1 instead of A when the data comes from IMPORTRANGE. Fill in the form and copy a formula that follows all of them. Nothing you type leaves your browser.

1. Your data

2. Filter rows (optional)

And a second condition (optional)

3. Totals by group (optional)

4. Sort and limit (optional)

Your QUERY formula

    Paste it into an empty cell with enough free space below and to the right: QUERY spills its results into the cells around it.

    Examples the generator builds

    All of these were pasted into Google Sheets on a small sales table (region in A, sales rep in B, date in C, amount in D, status in E) and returned the expected rows.

    You want Formula
    Sort by region, then by amount, largest first =QUERY(A1:F8, "select A, B, D order by A asc, D desc", 1)
    Total per region, largest first =QUERY(A1:F8, "select A, sum(D) group by A order by sum(D) desc", 1)
    Rows after a date =QUERY(A1:F8, "select B, C where C > date '2026-02-01'", 1)
    Amounts above the number in G1 =QUERY(A1:F8, "select B, D where D > "&G1, 1)
    Rows matching the text in G2 =QUERY(A1:F8, "select B where A = '"&G2&"'", 1)
    Rows after the date in G3 =QUERY(A1:F8, "select B, C where C > date '"&TEXT(G3, "yyyy-mm-dd")&"'", 1)
    Text with an apostrophe =QUERY(A1:F8, "select A where B = ""O'Neil""", 1)
    Ignore upper and lower case =QUERY(A1:F8, "select B where lower(A) = 'north'", 1)
    Two conditions =QUERY(A1:F8, "select A, B where D >= 100 and E = 'Paid'", 1)
    Empty cells =QUERY(A1:F8, "select B where E is null", 1)
    Top 3 by amount =QUERY(A1:F8, "select B, D order by D desc limit 3", 1)
    Another tab, whole columns =QUERY('Week 8 data'!A1:C, "select A, C where A is not null order by C asc", 1)
    Another spreadsheet =QUERY(IMPORTRANGE("spreadsheet-id", "'Week 8 data'!B1:C6"), "select Col2 where Col1 = 'Office'", 1)

    Mistakes the generator avoids

    We also ran the broken versions of these formulas. Some gave an error; others quietly returned the wrong rows.

    • A date without the word date. where C > '2026-02-01' returned no rows and no error.
    • The wrong case. where A = 'north' returned nothing, because the data said “North”. The same happened with contains. Use lower(), as in the example above.
    • A cell reference inside the quotes. "... where C > G3" failed with NO_COLUMN: G3. The query only knows the columns of the data, so the cell has to be joined from outside the quotes.
    • Text without quotes. where A = North failed with NO_COLUMN: North.
    • An apostrophe inside single quotes. where B = 'O'Neil' gave a PARSE_ERROR at “Neil”.
    • Lowercase column letters. select a, d failed with NO_COLUMN: a. The keywords can be in any case; the column letters must be capitals.
    • A column missing from group by. select A, B, sum(D) group by A failed with ADD_COL_TO_GROUP_BY_OR_AGG: B.

    More on sorting in our guide to QUERY ORDER BY with multiple columns, and on other tabs and files in QUERY from another sheet.

    Related guides