Create intermediate Works with: Any AI

Google Sheets QUERY Function Builder for Your Data

Table output Has example

Build a Google Sheets QUERY formula from plain English for your own columns, with select, where, group by, order by and label clauses explained.

The Open buttons send the prompt text as currently shown below to that site only when you click. Fill in the placeholders first.

[VERIFY] is an editorial flag, not a blank to fill. Wherever the prompt shows [VERIFY], check that item against a reliable source before you use it.

Rate this prompt

Loading ratings…

Build a Google Sheets QUERY formula from my description. Data range: [DATA_RANGE] on the tab [TAB_NAME]. Columns in order (letter and header): [COLUMN_LIST]. Data types I know about (text, number, date): [COLUMN_TYPES]. What I want to see: [PLAIN_ENGLISH_REQUEST]. Header rows in the range: [HEADER_ROWS].

Return:

1. The complete formula, ready to paste, using column letters (Col1 style is not needed unless my range requires it).

2. A clause-by-clause breakdown table with columns Clause, What it does here, The text in my formula.

3. Three variations: add a filter, add a total with group by, and sort the top 10.

4. The date and text matching rules I must follow inside a QUERY string (quotes, date format, contains versus equals), explained with my own columns.

5. How to make the formula read from cells instead of typed values, so my users can change filters without editing the formula.

6. A list of five typical errors (#VALUE!, "unable to parse query string", header mismatch, mixed types in a column) with a fix for each.

Never invent columns or values; use only those I gave. If my request is ambiguous, ask one question before writing. Note that formula behaviour should be tested on a small sample, and mark anything that depends on locale or settings [VERIFY].

Add a worked example with invented figures: an orders table with date, region, product and amount, summing amount by region for the last month.

Fill in before use

Optional: type your details and the prompt above updates. Nothing is saved or sent.

Replace each bracketed placeholder with your own details, then paste into Any AI or another assistant.

See an example result (fictional data)
Invented example
Data: Orders!A1:D500, columns A date, B region, C product, D amount.
Request: total amount by region since 1 March.

=QUERY(Orders!A1:D500, "select B, sum(D) where A >= date '2025-03-01' group by B order by sum(D) desc label sum(D) 'Total amount'", 1)

Clause table
select B, sum(D): the region and its total.
where A >= date '...': dates must be written yyyy-mm-dd inside the query.
group by B: one row per region.
order by sum(D) desc: biggest first.
label: renames the output header.

If you see a parse error, check quote marks first.

Illustrative only, made-up data. Your results will differ and must be reviewed.

Related prompts