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 the Google Sheets version instead? Open Sheets variant in workspace →

Working on a sheet you inherited? Run the Auditor on the whole file first — it flags every #REF!, #N/A, broken column pattern, and inconsistent formula in seconds, free, no signup.

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

Related tasks

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

Last reviewed: