Excel Subtotal Feature: How to Group and Total Data
In this article
The Subtotal feature in Excel inserts a summary row (or rows) after each group of related rows and can add an automatic outline with expand/collapse buttons, so you can see totals for each category and a grand total at a glance. It does this in one command instead of dozens of manual formulas. Before you run it, two things must be true: your data must be in a single continuous range with a header row, and the column you want to group by (for example Region or Category) must be sorted so identical values sit together. If it is not sorted, Subtotal will insert a new total every time the value changes, producing many tiny, useless blocks.
What You'll Need
- Excel on Windows, Mac, or Excel for the web. The Subtotal command lives in the ribbon on all of them; the exact tab layout can differ slightly by version and platform.
- A list with a header row in row 1 and no completely blank rows or columns inside it.
- Numeric columns you want summarized (sales, quantity, hours) plus one text column to group by.
- Your data sorted by the grouping column. Use Data > Sort, or the A–Z / Z–A buttons, before starting.
- A backup copy is wise the first time, because Subtotal inserts rows into your sheet. Undo works, but a copy is safer.
Step-by-Step
- Clean the range. Make sure row 1 holds column headers like Region, Product, and Sales. Remove blank rows within the data and make sure every data column has a header, because Subtotal uses the header text as the label for each summary row.
- Sort by the grouping column. Click any cell in the column you want to group by (say Region), then go to Data > Sort A to Z. If you need a secondary order, use Data > Sort and add a level. The important part is that all rows for the same region are adjacent.
- Select the whole table. Click inside the data and press Ctrl+A (Cmd+A on Mac), or drag to select every cell including headers. Do not select only one column, or Excel will summarize the wrong range. If your data is formatted as an Excel Table, convert it to a normal range first with Table Design > Convert to Range; Subtotal works on ranges, not tables.
- Open the Subtotal dialog. Go to the Data tab and click Subtotal in the Outline group. The dialog opens with three dropdowns: At each change in, Use function, and Add subtotal to.
- Set "At each change in". Choose your grouping column, for example Region. This tells Excel where to break and insert a summary row.
- Choose the function. Use function defaults to Sum. Change it to Count, Average, Max, Min, Product, Count Numbers, StDev, or Var depending on what you need. For headcounts, Count Numbers is usually the right pick; Count counts text entries too.
- Tick the columns to summarize. In Add subtotal to, check each numeric column you want totaled, for example Sales and Units. Leave ID or date columns unchecked unless you genuinely want them summarized.
- Keep the default options on the first run. Leave Replace current subtotals checked (it avoids stacking duplicate subtotal rows) and Leave Summary below data checked so a grand total appears at the bottom. Click OK.
- Check the result. Excel inserts a bold summary row after each group, with the grand total at the end. A gray outline area appears at the left with 1, 2, and 3 buttons and plus/minus signs.
- Use the outline buttons. Click 1 to show only the grand total, 2 to show each group's subtotal plus the grand total, and 3 to show every detail row again. Use the small plus and minus signs to expand or collapse individual groups.
- Add a second level if needed. Run Data > Subtotal again, pick a different "At each change in" column (say Product, within Region), and untick Replace current subtotals. You get nested subtotals and a deeper outline. Clicking 2 then shows the inner level.
- Remove subtotals when done. Reopen Data > Subtotal and click Remove All. This deletes every subtotal row and the outline in one go, leaving your original data. Do not delete the rows by hand; you will likely miss one or break the outline.
Common Mistakes
- Running Subtotal on unsorted data. The single most common failure. Identical values scattered through the sheet produce a separate subtotal for each block, so totals look wrong. Sort first, then subtotal.
- Using it on an Excel Table. Tables have their own Total Row and structured references; the Subtotal command is designed for plain ranges. Convert to Range first.
- Summarizing the wrong column. Leaving ID or a year column ticked gives you meaningless large numbers like a total of employee IDs.
- Typing SUBTOTAL formulas yourself and forgetting function numbers. If you build the formulas manually, the function argument is a number (9 for SUM, 2 for COUNT, 1 for AVERAGE, 4 for MAX, 5 for MIN). Selecting the function from the dropdown is less error-prone.
- Copying the data out and getting hidden rows. After collapsing the outline, copying the visible range can include hidden detail rows in some workflows. Paste carefully or collapse groups only after copying.
- Deleting subtotal rows manually. This leaves orphan outline levels and can misalign later subtotals. Use Remove All instead.
Tips
- The SUBTOTAL function ignores rows already hidden by the outline, which is exactly why it is used instead of SUM. If you filter the list, SUBTOTAL keeps recalculating only visible rows.
- To total a filtered list without any grouping, use the SUBTOTAL function with function number 109 (SUM) or 9 (SUM) depending on whether you want to ignore manually hidden rows.
- Format the summary rows once (bold, fill color, currency) and copy that formatting down with the Format Painter for a clean look.
- If you need the subtotal values as static data, copy the summary rows and paste as Values into a new sheet before removing the outline.
- For grouped totals that update automatically as data changes, a PivotTable is usually the better long-term tool. Subtotal is fastest for a one-off breakdown of an existing list.
- Widen column A slightly or the outline buttons can overlap your data labels.
Troubleshooting
- No outline buttons appear. Go to File > Options > Advanced and check that "Show outline symbols if an outline is applied" is enabled under the Display options for this worksheet. On Mac, look in Excel > Preferences > View.
- Totals appear after every row. The grouping column is not sorted, or contains trailing spaces so "North " and "North" are treated as different values. Clean the text with TRIM and sort again.
- Duplicate subtotal rows stack up. You ran Subtotal twice with Replace current subtotals unticked. Click Remove All, then run it once cleanly.
- The grand total row is missing. "Summary below data" was unchecked, or the grand total is hidden because outline level 1 is collapsed. Click the 1 button and check the bottom of the range.
- Subtotal is greyed out. Usually the data is inside an Excel Table, or the sheet is protected. Convert the table to a range or unprotect the sheet, then try again.
- Your totals do not match what you expect. Confirm the summarized column contains real numbers, not text that looks like numbers. Text values are ignored by SUM. Select the column and check the status bar count.
- If that did not work, press Ctrl+Z (Cmd+Z) to undo, save a copy, and rebuild the list in a fresh sheet with clean headers and sorted data before running Subtotal again.
Frequently Asked Questions
Does the Subtotal feature work on a filtered list?
Yes, the subtotal rows it inserts use the SUBTOTAL function, which by design ignores rows hidden by filters. Collapse or filter and the group summaries recalculate to show only visible rows.
Can I use Subtotal on more than one column at a time?
Yes. In the Add subtotal to list you can tick several numeric columns, and Excel will total all of them in the same summary row.
What is the difference between Subtotal and a PivotTable?
Subtotal edits the sheet in place by inserting rows, which is fast for a one-off view of an existing list. A PivotTable creates a separate summary object that you can rearrange and refresh as data changes, without touching the source rows.
Can I remove only some subtotal levels?
Excel's Remove All button clears every subtotal row and the outline at once. To keep one level and drop another, undo with Ctrl+Z and rerun Subtotal with only the level you want, or delete the unwanted summary rows one level at a time.
Why does my Subtotal command look greyed out?
Most often the range is an Excel Table or the worksheet is protected. Convert the table to a normal range or unprotect the sheet, then retry.
Can I subtotal in Excel for the web?
Yes, the Data tab in Excel for the web includes the Subtotal command. The dialog and outline behave the same way, though labels and ribbon layout can differ slightly by version and region.