Google Sheets QUERY Function Builder
Write SQL-like queries inside a sheet.
The Open buttons send the prompt text as currently shown below to that site only when you click. Fill in the placeholders first.
Write QUERY formulas for Google Sheets. Data range and column letters with their meaning: [DATA_RANGE_AND_COLUMNS]. Whether the first row is headers: [HEADER_ROWS]. What I want to report: [REPORT_NEEDS]. Sample data (fake): [SAMPLE_DATA]. Follow this example. Need: total sales per region for completed orders in 2026, highest first. Formula: =QUERY(Orders!A1:E, "select B, sum(D) where E = 'Completed' and year(A) = 2026 group by B order by sum(D) desc label sum(D) 'Total sales'", 1) Explanation: columns are referred to by letter; strings use single quotes; dates need the date keyword or functions; "label" renames the heading; 1 is the number of header rows. For my data, write formulas for each request, with explanations, plus these patterns: date range from cells (using TEXT(cell, "yyyy-mm-dd") in the query with the date keyword); text matching with "contains" and "matches"; multiple conditions; pivot with "pivot"; limiting rows; ignoring blanks; combining QUERY with data from two sheets using curly-bracket arrays; and formatting output headers. Also list common errors (mixed data types in a column cause empty results, wrong header count, column letters shift when a column is inserted in the query string, which is why to prefer named positions or helper notes). Provide test cases with expected output.
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)
Need: total sales per region for completed orders in 2026, highest first. =QUERY(Orders!A1:E, "select B, sum(D) where E = 'Completed' and year(A) = 2026 group by B order by sum(D) desc label sum(D) 'Total sales'", 1) Explanation: columns by letter, strings in single quotes, label renames the heading, 1 is the number of header rows. Date range from cells G1 and G2: ... where A >= date '"&TEXT(G1,"yyyy-mm-dd")&"' and A <= date '"&TEXT(G2,"yyyy-mm-dd")&"' Common failure: a mixed text and number column returns blanks. Test: North 5,400; South 3,100 for the sample.
Illustrative only, made-up data. Your results will differ and must be reviewed.