FormulaCraft

How to build a pivot-style summary with QUERY in Excel and Google Sheets

Topic:Pivot-style summaries (formula approach)

Heads up: Excel and Google Sheets do this differently.

Excel
=SUMIFS(C2:C10,B2:B10,E2)
Google Sheets
=QUERY(A1:C10,"SELECT B, SUM(C) WHERE A IS NOT NULL GROUP BY B LABEL SUM(C) 'Total'",1)

Try it with your data

Edit the grid or formula, then run it through a real spreadsheet engine — no signup.

Sample data — click any cell to edit

Runs server-side · free · no signup

Step by step

  1. 1Ensure your raw data has a header row in row 1 — for example: Date (A), Category (B), Amount (C).
  2. 2Click an empty cell at least two columns away from your data — say E1 — where you want the summary to appear.
  3. 3Enter =QUERY(A1:C10,"SELECT B, SUM(C) WHERE A IS NOT NULL GROUP BY B LABEL SUM(C) 'Total'",1). The trailing 1 tells QUERY your data has one header row.
  4. 4QUERY will spill a two-column result: one row per unique Category with the summed Amount in the second column.
  5. 5To sort the result by descending total, add ORDER BY SUM(C) DESC before the LABEL clause: "SELECT B, SUM(C) WHERE A IS NOT NULL GROUP BY B ORDER BY SUM(C) DESC LABEL SUM(C) 'Total'".

Tips

Need it for your exact data?

Describe your columns in plain English and get the precise formula for your sheet, with the right Excel or Sheets syntax.

Frequently asked

Does QUERY work in Excel?

No. QUERY is Google Sheets-only and uses the Google Visualization API Query Language. In Excel, use SUMIFS to aggregate by category, or build a PivotTable from the Insert menu.

Can QUERY produce multiple aggregations at once?

Yes. SELECT B, SUM(C), COUNT(C), AVG(C) GROUP BY B will give you sum, count, and average side by side in one formula output.

What happens if I add new rows to my source data?

Use an open-ended range like A1:C instead of A1:C10 so QUERY automatically picks up new rows without needing formula changes.

More on Pivot-style summaries (formula approach)

See all →

Formulas used

Written and reviewed by FormulaCraft Team. Each formula on this page is run through our verification engine before publishing.

Last reviewed: