Google Sheets functions / Google
Google function · Google Sheets
QUERY function
QUERY runs a database-style statement on a range. One formula can filter, group, sort and total data.
Syntax
=QUERY(data, query, [headers])On Excel: use GROUPBY. GROUPBY and PIVOTBY cover grouped totals. Power Query suits larger jobs.
Arguments
| Argument | Required | Meaning |
|---|---|---|
| data | Yes | The range to query. |
| query | Yes | The statement in quotes, using column letters. |
| headers | No | How many top rows are headers. |
Worked example
| A | B | C | |
|---|---|---|---|
| 1 | Region | Month | Sales |
| 2 | East | Jan | 1200 |
| 3 | West | Jan | 950 |
| 4 | East | Feb | 1400 |
| 5 | West | Feb | 800 |
| 6 | East | Feb | 300 |
=QUERY(A1:C6,"select A, sum(C) group by A label sum(C) 'Total'",1)Result: East 2900, West 1750
The statement groups rows by Region and adds the Sales column under a Total label.
Try it
QUERY is exclusive to Google Sheets, so the practice engine cannot run it. The result was checked by hand.
Availability
| Platform | Status |
|---|---|
| Excel | Not available. Use GROUPBY, PIVOTBY or Power Query. |
| Google Sheets | Available. |
Common mistakes
- Mixed text and numbers in a column can lead to blank results.
- Column letters must be capitals when the data is a range reference.
- Text values use single quotes inside the double-quoted statement.
Do it with AI
Paste this prompt into Copilot, Gemini or another assistant. Check the result on a small sample first.
Write a QUERY for A1:E500 that totals column E by column B for rows where column C is "Paid", sorted from highest total.