Cellwise Start free

Excel guide · 5 min read

How to sum by category in Excel

Quick answerList each category once and next to it use =SUMIF($B$2:$B$11,F2,$C$2:$C$11), where B holds the categories and C the amounts. In Excel 365, =HSTACK(UNIQUE(B2:B11),SUMIF(B2:B11,UNIQUE(B2:B11),C2:C11)) builds the whole summary in one formula. Then check that the category totals add up to the grand total: if they don't, some categories are spelled differently.

Sample data

Every result on this page was calculated from this sheet by the same spreadsheet engine the Cellwise app uses.

ABCDEFG
1DateCategoryAmountClean categoryCategoryTotal
2Oct 1, 2026Travel412.8TravelTravel569.2
3Oct 2, 2026Software49SoftwareSoftware289
4Oct 3, 2026Meals38.5MealsMeals125.45
5Oct 7, 2026Office supplies126.35Office suppliesOffice supplies145.25
6Oct 9, 2026Travel 296.4Travel
7Oct 12, 2026meals64.2meals
8Oct 15, 2026Software240Software
9Oct 20, 2026Meals22.75Meals
10Oct 24, 2026Travel156.4Travel
11Oct 28, 2026Office supplies18.9Office supplies

Download this sheet as an Excel practice file (.xlsx)

Method 1: SUMIF against a list of categories

Type each category once in column F, then put SUMIF next to the first one and fill down. SUMIF looks through the categories in B, finds the ones equal to F2, and adds the matching amounts from C. The dollar signs keep both ranges fixed while F2 changes to F3, F4 and F5.

This works in every version of Excel, and it is the right choice when the list of categories is fixed, such as a budget with set lines, or when you want them in a particular order. SUMIF is not case-sensitive, so the Meals total includes the row typed as "meals".

If you need a second condition, such as one category in one month, switch to SUMIFS, which puts the amounts first: =SUMIFS($C$2:$C$11,$B$2:$B$11,F2,$A$2:$A$11,">="&DATE(2026,10,1)).

=SUMIF($B$2:$B$11,F4,$C$2:$C$11)

Result: 125.45

$125.45 for Meals: $38.50 + $64.20 + $22.75, including the lowercase "meals" row.

Check the totals: stray spaces split a category

Always compare the category totals with the grand total. Here the expenses add up to $1,425.30 but the four category totals only reach $1,128.90. The missing $296.40 is the row in B6, where "Travel " has a trailing space, so SUMIF does not treat it as Travel. Spaces like this come from imports, copy-paste and dropdown lists built from untidy data, and they are invisible in the cell.

The lasting fix is a clean column. Put =TRIM(B2) in D2 and fill down; TRIM removes leading, trailing and doubled spaces. Then point SUMIF at column D instead of B: =SUMIF($D$2:$D$11,F2,$C$2:$C$11) gives Travel its full $865.60. SUMIF cannot take TRIM(B2:B11) as its range, because it needs a real range. If you can't add a column, =SUMPRODUCT((TRIM($B$2:$B$11)=F2)*$C$2:$C$11) does the cleaning inside the formula.

Case is not the problem it seems. SUMIF, UNIQUE and PivotTables all treat "Meals" and "meals" as one category. It only matters if you need them apart, and then you need EXACT inside SUMPRODUCT.

=SUM(C2:C11)-SUM(G2:G5)

Result: 296.4

$296.40 is not counted in any category: the "Travel " row with a trailing space.

Method 2: an automatic summary with UNIQUE and SUMIF

In Excel 365, you don't have to type the category list. UNIQUE pulls each category once from the clean column, SUMIF totals each one, and HSTACK puts the two side by side. The result spills into as many rows as there are categories, and a new category in the data gets its own row automatically.

Run UNIQUE on the trimmed column, not the original one. =UNIQUE(B2:B11) returns five categories here, because "Travel " counts as its own value. Leave the cells below and to the right of the formula empty, or it shows #SPILL!.

UNIQUE needs Excel 365 or 2021, and HSTACK needs 365 or 2024. Without HSTACK, put =UNIQUE(D2:D11) in F2 and =SUMIF(D2:D11,F2#,C2:C11) in G2; F2# refers to the whole spilled list.

=HSTACK(UNIQUE(D2:D11),SUMIF(D2:D11,UNIQUE(D2:D11),C2:C11))

Result: spills 4 rows × 2 columns

Travel865.6
Software289
Meals125.45
Office supplies145.25

Four rows: Travel $865.60, Software $289.00, Meals $125.45 and Office supplies $145.25, in the order each category first appears.

Sort the summary by total

Wrap the summary in SORT to put the biggest category first. SORT's second argument is the column to sort by (2, the totals) and the third is the order (-1 for largest first). LET names the category list once, so UNIQUE runs once and the formula stays readable.

For alphabetical order instead, sort the categories before totalling them: =LET(c,SORT(UNIQUE(D2:D11)),HSTACK(c,SUMIF(D2:D11,c,C2:C11))). To add a grand total row underneath, stack it on with VSTACK: =VSTACK(summary,HSTACK("Total",SUM(C2:C11))).

=LET(c,UNIQUE(D2:D11),SORT(HSTACK(c,SUMIF(D2:D11,c,C2:C11)),2,-1))

Result: spills 4 rows × 2 columns

Travel865.6
Software289
Office supplies145.25
Meals125.45

Travel $865.60, Software $289.00, Office supplies $145.25, Meals $125.45: largest first.

Method 3: a PivotTable (no formulas)

A PivotTable builds the same summary with a few clicks and works in every version. It is the best pick when you also want to slice by month, filter, or drill into the rows behind a total by double-clicking it.

Two things catch people out. A PivotTable does not update when the data changes: right-click it and choose Refresh, or use Data > Refresh All. And it shows "Travel" and "Travel " as two separate rows, so clean the category column first, just as with the formulas.

  1. Click any cell in the data and press Ctrl+T to turn it into a table, so new rows are included on refresh.
  2. Go to Insert > PivotTable, choose New Worksheet and click OK.
  3. Drag Category to Rows and Amount to Values.
  4. If it says Count of Amount, click it, choose Value Field Settings and pick Sum. Count usually means some amounts are text or blank.
  5. To sort by total, right-click any total and choose Sort > Sort Largest to Smallest.

Common mistakes

Not checking that the categories add up to the total

Compare =SUM(amounts) with the sum of the category totals. A gap means a category is misspelled or has stray spaces.

Using a wildcard like "Travel*" to catch the spaces

It also catches "Travel insurance" or any other category that starts the same way. Clean the column with TRIM instead.

Relative ranges in a filled-down SUMIF

Without dollar signs, B2:B11 slides to B3:B12 and further down each row, quietly dropping rows. Use $B$2:$B$11 and $C$2:$C$11.

Forgetting to refresh the PivotTable

PivotTables keep the old totals until you refresh. Right-click > Refresh, or Data > Refresh All before you send the report.

FAQ

How do I sum values by category in Excel?

Use =SUMIF(category_range,category,amount_range) next to each category, for example =SUMIF($B$2:$B$11,F2,$C$2:$C$11). In Excel 365, UNIQUE can list the categories for you so the summary grows with the data.

How do I get a list of categories with their totals automatically?

In Excel 365: =HSTACK(UNIQUE(B2:B11),SUMIF(B2:B11,UNIQUE(B2:B11),C2:C11)). In older versions, use a PivotTable, or copy the categories, run Data > Remove Duplicates on the copy and add SUMIF next to it.

Why is my SUMIF total for a category too low?

Usually some cells in the category column have extra spaces or a slightly different spelling, or some amounts are numbers stored as text. Check with =LEN() on the category and =ISNUMBER() on the amount.

Is SUMIF case-sensitive?

No. "Meals", "MEALS" and "meals" are added together. For a case-sensitive total, use =SUMPRODUCT(EXACT(B2:B11,F2)*C2:C11).

Can I sum by category and month?

Yes, with SUMIFS and a date range: =SUMIFS(C:C,B:B,F2,A:A,">="&start,A:A,"<="&end). A PivotTable with Date grouped by month in Columns does the same without formulas.

Functions used

Related guides

Updated