How to Sum by Category in Excel
By ExcelReady TeamUpdated 6 min read
The short answer
To sum by category in Excel, list each category once, then use SUMIF next to it: =SUMIF($A$2:$A$8,D2,$B$2:$B$8) adds the amounts in column B for the category named in D2. Fill it down for a full summary. In Excel 2021 or Microsoft 365, =UNIQUE(A2:A8) builds the category list for you, and a PivotTable does the same job without formulas.
Key takeaways
- A category summary has two parts: a list of each category once, and a SUMIF next to each one.
- Lock the ranges with $ signs and leave the category cell unlocked so the formula fills down.
- In Excel 2021 or Microsoft 365, =SORT(UNIQUE(A2:A8)) builds and sorts the list automatically.
- Check that the category totals add up to the grand total; a gap means a spelling or spacing difference.
- Use SUMIFS when you need a second condition, such as category and month.
On this page+
To sum by category in Excel, you need two things: a list of each category once, and a SUMIF next to each name that adds up its amounts. That gives you a clean summary, such as total spend on Travel, Meals and Office, that updates whenever the data changes. This guide builds one step by step, then shows the automatic UNIQUE version, percent of total, a second condition and the PivotTable alternative.
The sample data#
Every example uses this expense list in A1:B8:
| A | B | |
|---|---|---|
| 1 | Category | Amount |
| 2 | Travel | 120 |
| 3 | Meals | 45 |
| 4 | Office | 80 |
| 5 | Travel | 300 |
| 6 | Meals | 60 |
| 7 | Software | 99 |
| 8 | Office | 35 |
The categories repeat in no particular order, which is how real data usually looks. The finished summary should show Travel 420, Meals 105, Office 115 and Software 99, for a grand total of 739.
Step 1: List each category once#
Type each category once in a new column, starting in D2: Travel, Meals, Office, Software. Add a header such as "Category" in D1. With a short list, typing is fine.
For a longer list, copy column A to column D, select it, and use Data > Remove Duplicates. Excel deletes the repeats and leaves one of each. The catch is that this list doesn't update: if a new category appears in the data later, you have to add it yourself.
Step 2: Total each category with SUMIF#
SUMIF adds the numbers in one range when the matching cells in another range meet a condition. Here the condition is "the category equals the name in column D". In E2, type:
=SUMIF($A$2:$A$8,D2,$B$2:$B$8)| Part | What it does |
|---|---|
$A$2:$A$8 | The category column to check |
D2 | The category to match (Travel) |
$B$2:$B$8 | The amounts to add |
Press Enter: E2 shows 420 (120 + 300). Then fill down to E5 (Windows: Ctrl+D; Mac: ⌘D). The $ signs lock the two ranges so they don't slide down, while D2 has no $ and changes to D3, D4 and D5:
| D | E | |
|---|---|---|
| 1 | Category | Total |
| 2 | Travel | 420 |
| 3 | Meals | 105 |
| 4 | Office | 115 |
| 5 | Software | 99 |
SUMIF ignores capitals, so "travel" in column D still matches "Travel". For a full walk-through of SUMIF, read how to use SUMIF, or see the SUMIF function guide.
Step 3: Check the totals add up#
Add the summary and compare it with the original column:
=SUM(E2:E5)It should equal =SUM(B2:B8), which is 739. If the summary is smaller, some rows didn't match any category in your list. The usual causes are a missing category, a typo such as "Meal" instead of "Meals", or an extra space, like "Travel " with a trailing space. SUMIF needs an exact match, so those rows are left out without any warning. Clean the column with TRIM, fix the typos, and the totals will agree.
Build the category list automatically with UNIQUE#
In Excel 2021 or Microsoft 365, the UNIQUE function builds the list for you and updates it when the data changes. In D2, type:
=UNIQUE(A2:A8)The result spills into the cells below: Travel, Meals, Office, Software, in the order they first appear. To sort them alphabetically, wrap it in SORT: =SORT(UNIQUE(A2:A8)).
Then point SUMIF at the whole spilled list with the # sign, which means "the full spill range starting at D2":
=SUMIF(A2:A8,D2#,B2:B8)Type this once in E2 and it spills a total next to every category. Add a new category to the data and both columns grow on their own. If you see #SPILL!, something is blocking the cells below; clear them. The UNIQUE function guide has more examples, and older versions of Excel need the manual list from Step 1.
Percent of total and the biggest category#
Once you have the totals, a share of the total is one division away. In F2, type this and fill down, then format the column as a percentage:
=E2/SUM($E$2:$E$5)Travel is 420 / 739, about 57% of all spending. To find the biggest category by formula, combine INDEX and MATCH with MAX: =INDEX(D2:D5,MATCH(MAX(E2:E5),E2:E5,0)) returns Travel.
Sum by category with a second condition#
When you need totals by category and something else, such as a month or a region, switch to SUMIFS. Say column C holds the expense date. Travel spending in January 2024 is:
=SUMIFS(B2:B8,A2:A8,"Travel",C2:C8,">="&DATE(2024,1,1),C2:C8,"<="&DATE(2024,1,31))SUMIFS puts the sum range first, then a range and criteria for each condition. A grid with categories down the side and months across the top is a common report built this way; see how to sum by month and how to sum by date range. If your categories are buried inside longer descriptions, use wildcards as shown in SUMIF contains text.
Sum by category with a PivotTable#
A PivotTable gives the same totals without any formulas. Click anywhere in the data, go to Insert > PivotTable, and choose a new sheet. Drag Category to Rows and Amount to Values. Excel lists each category once and shows its sum, with a grand total at the bottom.
PivotTables are fast and easy to rearrange, but they don't update until you refresh them (right-click > Refresh). SUMIF is better for a report with a fixed layout that must always be current, while a PivotTable is better for exploring. Many job tests ask for both, so it is worth knowing each.
Practise it#
A category summary is one of the most common tasks in any Excel job. Practise SUMIF in a live spreadsheet: you type the formula and it checks it instantly. Then build a full summary table in the pivot-style summary lesson. When you're ready, try the data analyst Excel test.
Try it yourself
This is a live spreadsheet. Type the formula in the green cell and press Enter.
D2 holds the category Travel. In E2, use SUMIF to total the Amount (B2:B8) for the category in D2.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Amount | Total | ||||
| 2 | Travel | |||||
| 3 | ||||||
| 4 | ||||||
| 5 | ||||||
| 6 | ||||||
| 7 | ||||||
| 8 | ||||||
| 9 | ||||||
| 10 | ||||||
| 11 |
Tip: Check the categories in A2:A8, match the name in D2, and add the amounts in B2:B8.
Practise this in a lesson
Frequently asked questions
How do I sum values by category in Excel?
List each category once in a column, then next to the first one type =SUMIF($A$2:$A$8,D2,$B$2:$B$8) and fill down. Each row shows the total for its category.
How do I get a list of unique categories in Excel?
In Excel 2021 or Microsoft 365, use =UNIQUE(A2:A8), or =SORT(UNIQUE(A2:A8)) for an alphabetical list. In older versions, copy the column and use Data > Remove Duplicates.
How do I sum by category and month?
Use SUMIFS with one condition for the category and two for the dates: =SUMIFS(B2:B8,A2:A8,"Travel",C2:C8,">="&DATE(2024,1,1),C2:C8,"<="&DATE(2024,1,31)).
Should I use SUMIF or a PivotTable to sum by category?
Use SUMIF when you want totals in a fixed layout that update on their own. Use a PivotTable for a quick summary you can rearrange, but remember to refresh it when the data changes.
Why does one category total look too low?
Some rows probably have a slightly different spelling, such as Travel with a trailing space. SUMIF needs an exact match apart from capitals, so clean the column with TRIM or fix the typos.