Skip to content

How to sum by category in Excel and Google Sheets

Topic:SUM & aggregation
Excel & Google Sheets
=SUMIF(A2:A100,"Fruit",B2:B100)

Verified example

Computed by a real spreadsheet engine on the sample data below.

CategorySales
Fruit300
Vegetable150
Fruit200
Dairy400
Vegetable120

=SUMIF(A2:A100,"Fruit",B2:B100)500

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. 1Lay out the data with a category column (A) and a value column (B).
  2. 2Sum one category: =SUMIF(A2:A100,"Fruit",B2:B100) — range to test, criterion, range to sum.
  3. 3Point the criterion at a cell instead of hard-coding it: =SUMIF($A$2:$A$100,D2,$B$2:$B$100), with category names listed in column D — copy down for a reusable summary table.
  4. 4Generate the category list automatically: in Sheets or Excel 365, =UNIQUE(A2:A100) spills every distinct category; put the SUMIF beside it and the summary maintains itself as new categories appear.
  5. 5Add more conditions with SUMIFS: =SUMIFS(C2:C100,A2:A100,"Fruit",B2:B100,"Jan") totals rows that match category AND month. Note SUMIFS takes the sum range FIRST.

Tips

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

How do I sum by category and month (two criteria)?

Use SUMIFS, which accepts unlimited condition pairs and takes the sum range first: =SUMIFS(C2:C100,A2:A100,"Fruit",B2:B100,"Jan").

How do I build a summary table for every category automatically?

Spill the distinct labels with =UNIQUE(A2:A100), then next to it =SUMIF($A$2:$A$100,D2#,$B$2:$B$100) (Excel 365) or copy the SUMIF down (any version). New categories appear in the table automatically.

Can I match categories with wildcards?

Yes: =SUMIF(A2:A100,"Fr*",B2:B100) sums every category beginning with "Fr"; "*berry" matches anything ending in berry; "?" stands for a single character.

Is SUMIF case-sensitive?

No — "fruit" and "Fruit" match the same rows. For a case-sensitive sum use SUMPRODUCT with EXACT: =SUMPRODUCT(--EXACT(A2:A100,"Fruit"),B2:B100).

When should I use a PivotTable instead of SUMIF?

Use a PivotTable for ad-hoc exploration of many categories and dimensions; use SUMIF/SUMIFS when the summary must live inside a report layout and update instantly without a refresh.

More on SUM & aggregation

See all →

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

Last reviewed: