To add subtotals in Excel, sort your data by the column you want to group, then go to Data > Subtotal. Choose the grouping column in At each change in, pick a function such as Sum, tick the columns to total and click OK. To remove subtotals, open Data > Subtotal again and click Remove All.
| Task | Where to go |
|---|---|
| Add subtotals to a list | Sort first, then Data > Outline > Subtotal |
| Remove subtotals from a list | Data > Subtotal > Remove All |
| Hide all subtotals in a pivot table | Design > Subtotals > Do Not Show Subtotals |
| Hide subtotals for one pivot field | Field Settings > Subtotals & Filters > None |
| Total only visible (filtered) rows | =SUBTOTAL(109,D2:D100) |
| Subtotal with a condition | SUBTOTAL helper column plus SUMIFS |
How do I add subtotals in Excel?
The Subtotal command inserts a total row after each group in a sorted list, plus a grand total at the bottom, and adds outline buttons so you can collapse the detail. It's quick, but the data must be a normal range sorted by the grouping column.

We'll use this sales list in A1:C7:
| A: Region | B: Product | C: Sales | |
|---|---|---|---|
| 2 | North | Laptops | 4,200 |
| 3 | North | Monitors | 1,800 |
| 4 | South | Laptops | 3,100 |
| 5 | South | Monitors | 2,250 |
| 6 | West | Laptops | 5,000 |
| 7 | West | Monitors | 950 |
- Check the list has one header row, no blank rows and no blank columns.
- Click any cell in column A, then choose Data > Sort A to Z. Our guide to sorting A to Z in Excel covers multi-level sorts if you need them.
- Go to Data > Outline > Subtotal.
- In At each change in, choose Region.
- In Use function, choose Sum.
- In Add subtotal to, tick Sales.
- Leave Replace current subtotals and Summary below data ticked, then click OK.
Excel inserts North Total (6,000), South Total (5,350) and West Total (5,950), then a Grand Total of 17,300. Each total row uses a formula such as =SUBTOTAL(9,C2:C3), so the grand total doesn't double-count the group totals.
Use the outline numbers at the top left of the sheet to change the view: 1 shows only the grand total, 2 shows the group totals, and 3 shows everything. Microsoft's guide to inserting subtotals in a list of data explains every option in the dialog.
What we commonly see: the Subtotal button is greyed out because the data is formatted as an Excel table. Subtotals don't work inside tables. Click in the table, choose Table Design > Convert to Range, and then run Subtotal. Or skip the command and use the table's Total Row or a PivotTable.
How do I subtotal in Excel with multiple criteria?
Run the Subtotal command twice to create nested subtotals, for example by region and then by product within each region.
- Sort by Region, then by Product, using Data > Sort with two levels.
- Run Data > Subtotal with At each change in set to Region, and click OK.
- Run Data > Subtotal again with At each change in set to Product.
- Clear Replace current subtotals, then click OK.
The outline now has four levels. Always add the outer group first and work inwards.
If you only need the numbers rather than a reformatted list, SUMIFS is cleaner and keeps your data intact. North laptop sales: =SUMIFS(C2:C7,A2:A7,"North",B2:B7,"Laptops") returns 4,200. A PivotTable with Region and Product in Rows and Sales in Values gives the same multi-level subtotals with no formulas at all, and it's easier to rearrange later.
How do I remove subtotals in Excel?
Click any cell in the subtotalled range, go to Data > Subtotal and click Remove All. Excel deletes every subtotal and grand total row and removes the outline, leaving your original data.
Don't delete subtotal rows by hand. It's slow, easy to miss one, and leaves the outline grouping behind. If you've already done that, remove the leftover grouping with Data > Ungroup > Clear Outline.
If Remove All seems to do nothing, check that the active cell is inside the subtotalled range. If the totals are typed numbers or SUM formulas that someone added manually, Remove All won't recognise them; delete those rows yourself, or filter for "Total" in the label column and delete the visible rows.
How do I remove or hide subtotals in a pivot table?
Click anywhere in the PivotTable, go to the Design tab, click Subtotals and choose Do Not Show Subtotals. Every subtotal row disappears, while the grand total stays.
The same menu offers Show all Subtotals at Bottom of Group and Show all Subtotals at Top of Group. To remove grand totals as well, use Design > Grand Totals > Off for Rows and Columns. Microsoft's article on showing or hiding subtotals and totals in a PivotTable covers both menus.
To hide subtotals for one field only, leaving the rest:
- Click an item in that row field, not a value.
- Go to PivotTable Analyze > Active Field > Field Settings.
- On the Subtotals & Filters tab, select None.
- Click OK.
Microsoft's guide to subtotal and total fields in a PivotTable confirms these per-field steps. For a flat report with no subtotals at all, combine Do Not Show Subtotals with Design > Report Layout > Show in Tabular Form and Repeat All Item Labels. That layout copies cleanly into other sheets, and our guide to converting a pivot table to a normal table shows how to turn it into static data.
How does the SUBTOTAL function work?
SUBTOTAL calculates a sum, count, average or other summary while ignoring rows hidden by a filter. Its syntax is =SUBTOTAL(function_num,ref1,...), where function_num chooses the calculation.

| Calculation | Includes manually hidden rows | Ignores manually hidden rows |
|---|---|---|
| AVERAGE | 1 | 101 |
| COUNT | 2 | 102 |
| COUNTA | 3 | 103 |
| MAX | 4 | 104 |
| MIN | 5 | 105 |
| SUM | 9 | 109 |
Rows hidden by a filter are always excluded, whichever code you use. The difference between 9 and 109 only matters for rows you've hidden by right-clicking and choosing Hide. SUBTOTAL also ignores other SUBTOTAL results in its range, which is why grand totals don't double-count. Microsoft's SUBTOTAL function reference lists all 22 codes. If a filter is hiding rows you expect to see in the total, our guide to clearing filters in Excel can help.
How do I use SUBTOTAL with IF in Excel?
SUBTOTAL has no criteria argument, so combine it with a helper column. This gives you a "subtotal if" that totals only visible rows that also meet a condition.

- In D2, enter
=SUBTOTAL(103,A2)and copy it down to D7. It returns 1 for visible rows and 0 for rows hidden by a filter. - Use SUMIFS with the helper column as an extra condition:
=SUMIFS(C2:C7,D2:D7,1,B2:B7,"Laptops").
Filter Region to North and South, and the formula returns 7,300, the laptop sales in the visible rows only. Clear the filter and it returns 12,300. The same helper works with COUNTIFS and AVERAGEIFS, and our guide to COUNTIFS with multiple criteria shows how to stack more conditions.
Without a helper column, this single formula does the same job in every version:
=SUMPRODUCT(SUBTOTAL(109,OFFSET(C2,ROW(C2:C7)-ROW(C2),0))*(B2:B7="Laptops"))
It's harder to read, and OFFSET is volatile, so prefer the helper column in large workbooks.
Advanced nuance: for a formula-only subtotal report, Microsoft 365 has GROUPBY, which groups and totals a range in one dynamic formula, such as =GROUPBY(A2:A7,C2:C7,SUM). GROUPBY is only in Microsoft 365, not in Excel 2024 or earlier, as our comparison of Excel 2024 vs Excel in Microsoft 365 explains. The Subtotal command, SUBTOTAL function and PivotTable subtotals work the same in Excel 2016 through 2024, and in Office 2024 Professional Plus for Windows.
Frequently asked questions
Why is the Subtotal button greyed out in Excel?
The data is almost certainly an Excel table, where the Subtotal command is unavailable. Click inside the table and choose Table Design > Convert to Range, then try again. The button is also unavailable while you're editing a cell, or if the sheet is protected. Press Esc and check Review > Unprotect Sheet.
Why are my subtotals in the wrong places?
The data wasn't sorted by the grouping column first. The Subtotal command inserts a total every time the value changes, so an unsorted list gets a total row after almost every record. Click Remove All, sort by the grouping column with Data > Sort A to Z, then run Subtotal again.
Can I copy only the subtotal rows?
Yes. Click outline level 2 to show only the subtotals, select the visible range, then press Alt+; to select visible cells only. Copy with Ctrl+C and paste elsewhere. Without Alt+;, Excel copies the hidden detail rows too, because collapsing an outline only hides them.
What is the difference between 9 and 109 in SUBTOTAL?
Both calculate a SUM and both ignore rows hidden by a filter. Code 9 includes rows you've hidden manually with the Hide command, while 109 excludes them. Use 109 when you want the total to match exactly what's visible on screen, whichever way the rows were hidden.
Related guides
- How to convert a pivot table to a normal table
- How to sort a pivot table by values
- How to clear or remove filters in Excel
- COUNTIFS with multiple criteria in Excel
Links in this guide
| Link | Type | Why it helps |
|---|---|---|
| Microsoft Support: Insert subtotals in a list of data | External | Every option in the Subtotal dialog |
| Microsoft Support: Show or hide subtotals and totals in a PivotTable | External | Design tab Subtotals and Grand Totals menus |
| Microsoft Support: Subtotal and total fields in a PivotTable | External | Turning off subtotals for one field |
| Microsoft Support: SUBTOTAL function | External | All function_num codes |
| Sort A to Z in Excel | Internal | Sorting before running Subtotal |
| Convert a pivot table to a normal table | Internal | Turn a flat pivot into static data |
| Clear filters in Excel | Internal | When filtered rows change SUBTOTAL results |
| COUNTIFS with multiple criteria | Internal | More conditions for subtotal-if formulas |
| Excel 2024 vs Excel in Microsoft 365 | Internal | Why GROUPBY needs Microsoft 365 |
| Office 2024 Professional Plus for Windows | Internal | Excel 2024 with full subtotal and PivotTable tools |
| Sort a pivot table by values | Internal | Ordering pivot subtotals by size |
