Subtotals in Excel: How to Summarize Data the Right Way
What You'll Be Able to Summarize, and What Your Data Needs Before You Add Subtotals in Excel
Most people who struggle with subtotals in Excel are solving the wrong problem. They're fighting the tool when the real issue is the data structure underneath it. Before you touch a single formula or ribbon button, your data needs to be sorted by the column you want to group. Skip that step and everything downstream breaks. I've watched analysts spend an hour troubleshooting a subtotal setup that was broken in the first thirty seconds.
There are two completely different tools in Microsoft Excel that both get called "subtotals," and mixing them up is where most confusion starts. One is a Ribbon feature under the Data tab that inserts summary rows directly into your sheet. The other is the SUBTOTAL function, a formula you write yourself that calculates on the fly. They're useful in different situations, and this guide covers exactly when to use each one.
|
| The Subtotal feature groups your data by a chosen column and adds collapsible outline levels — useful for printable summaries without altering raw data. |
The Two Tools That Both Go by "Subtotals" (and How to Pick the Right One)
The subtotal feature (Data tab → Subtotal) physically inserts rows into your dataset and gives you outline levels you can collapse and expand. It's fast for a one-off summary. The SUBTOTAL function is a formula: =SUBTOTAL(function_num, ref). It recalculates dynamically based on what's visible in a filtered range, which is what you want in a live dashboard. These aren't interchangeable. One is for exploration; the other is for production.
Step 1: Use the Subtotal Feature in Excel to Collapse and Group Your Data Automatically
Once your data is sorted by the column you want to group on (say, Region in a "Regional Logistics Orders Q1–Q2 2025" dataset), you're ready to let Excel do the heavy lifting.
- Click anywhere inside your dataset.
- Go to Data → Subtotal in the Outline group.
- In the dialog, set At each change in to your grouping column (e.g., Region).
- Choose your aggregate function: SUM, COUNT, AVERAGE, etc.
- Check the columns you want summarized, then click OK.
Excel inserts subtotal rows for each group and adds outline levels on the left side of the sheet. The numbered buttons (1, 2, 3) let you collapse rows to show only grand totals, group totals, or all detail. This is the group and outline system, and it's genuinely useful for printing or presenting a summary without destroying your underlying data view.
Nested subtotals work too. You can subtotal by Region and then by Product within each Region by running the feature twice, unchecking "Replace current subtotals" on the second pass.
Why the Subtotals Button Is Grayed Out (and the Fix That Takes 10 Seconds)
The subtotal feature doesn't work on Excel Tables. If your data is formatted as a Table (the kind with banded rows you get from Ctrl+T), the Subtotal button will be grayed out.
To fix it: right-click inside the Table → Table → Convert to Range. The Subtotal button becomes available immediately.
That one grayed-out button is responsible for a disproportionate share of "Excel is broken" complaints. It's not broken. It won't let you insert subtotal rows into a structured Table because doing so breaks the Table's integrity, and that leads directly to why I prefer formulas over the Ribbon tool for anything beyond a quick look.
Step 2: Write the SUBTOTAL Function Formula in Excel When You Need More Control
With the Ribbon approach covered, the SUBTOTAL function is where real flexibility starts. The syntax is:
=SUBTOTAL(function_num, ref1, [ref2], ...)
The function_num argument tells Excel what calculation to run. Here are the most common values and a detail most tutorials skip entirely:
| Function Number | Calculation | Ignores Hidden Rows? |
|---|---|---|
| 1 | AVERAGE | Filtered rows only |
| 2 | COUNT | Filtered rows only |
| 9 | SUM | Filtered rows only |
| 101 | AVERAGE | Filtered + manually hidden |
| 102 | COUNT | Filtered + manually hidden |
| 109 | SUM | Filtered + manually hidden |
So for a filtered list of order amounts in column D, you'd write =SUBTOTAL(9, D2:D500).
SUBTOTAL also ignores other SUBTOTAL results in the same range, which means no double-counting when you have summary rows mixed into your data. A plain SUM formula counts everything, including intermediate totals. That silent double-count is one of the more embarrassing errors to explain to a finance director.
The function ignores filtered-out rows automatically. That's the whole point in a dashboard context: your total updates the moment someone applies a filter, no manual adjustment needed.
Function numbers 1–11 include manually hidden rows in the calculation. Function numbers 101–111 exclude them. If you're building a dashboard where users might hide rows manually rather than filtering, use 109 instead of 9. The wrong choice returns incorrect totals silently, with no error message.
Step 3: Decide Whether Subtotals, a PivotTable, or GROUPBY Actually Fits Your Goal
Now that you know both tools, the real question is which one your situation actually calls for. Here's how I think about it after 12+ years of building dashboards in logistics and finance.
Use the subtotal feature when you need a fast, printable on-sheet summary and you won't be touching the data again. It's disposable analysis. Use the SUBTOTAL function when you're building a dashboard or report template that filters dynamically; it belongs inside a named Table with structured references, not a plain range.
Use a PivotTable when you need to slice the same data across multiple dimensions without rewriting formulas. For cross-tab analysis (say, sales by Region and Product Category), a PivotTable does in three clicks what a formula setup takes an afternoon to build. The GROUPBY function in Microsoft 365 is worth knowing as of 2026. It brings PivotTable-style grouping into a formula that spills into a dynamic array, giving you clean, no-click summaries that update automatically. I'd still reach for a PivotTable first for most exploratory work, but GROUPBY is the right call when you need the output embedded in a larger formula chain.
Common Mistakes When You Add Subtotals in Excel (Including the Sort Step Everyone Skips)
The most common mistake is also the most avoidable: running the subtotal feature before sorting the data. If your Region column isn't sorted, Excel creates a separate subtotal group for every instance of each region in the sheet. You end up with six "North" groups instead of one. Sort first. Always.
Second: using SUM in a filtered range instead of SUBTOTAL. SUM counts everything regardless of filter state. Replacing SUM with =SUBTOTAL(9, ...) takes ten seconds and eliminates the problem permanently.
Third: changing the subtotal grouping without removing existing subtotals first. Go to Data → Subtotal → Remove All before re-running the feature with new settings. Skipping this creates nested subtotals you didn't ask for, and they're not the useful kind.
One more, specific to formula-based subtotaling: if your source data was imported or pasted and numeric fields got stored as text, SUBTOTAL and SUMIFS will return zero with no error message. No red flag, just silently wrong numbers. The fix belongs upstream: enforce data types in Power Query before the data reaches the worksheet. If you're new to getting data in shape before analysis, the guide on preparing data for analysis in Excel is worth reading before you build your next subtotal setup.
Frequently Asked Questions
Why is the Subtotals button grayed out in Excel?
The Subtotal button is grayed out because your data is formatted as an Excel Table. The subtotal feature can't insert rows into a Table's structure. Right-click inside the Table, go to Table → Convert to Range, and the button will become active immediately.
What's the difference between the SUBTOTAL function and the Subtotal feature in Excel?
The Subtotal feature (Data tab) physically inserts grouped summary rows into your worksheet and adds outline levels for collapsing. The SUBTOTAL function is a formula (=SUBTOTAL(function_num, ref)) that calculates dynamically based on which rows are currently visible after filtering. Use the feature for quick one-off summaries; use the function for live dashboards and templates.
Should I use subtotals or a PivotTable in Excel?
Use subtotals when you need a simple on-sheet summary that stays close to your raw data. Use a PivotTable when you need to group, filter, and cross-tabulate across multiple fields without rewriting formulas. For most analytical work beyond basic grouping, a PivotTable is faster and easier to update.
How do I remove subtotals in Excel?
Go to Data → Subtotal, then click the Remove All button in the dialog box. This strips out all inserted subtotal rows and restores your original dataset. Always do this before re-running the subtotal feature with a different grouping column.
Join the conversation