The SUBTOTAL function in Excel calculates aggregations like SUM, AVERAGE, or COUNT on filtered data while ignoring other SUBTOTAL results, making it ideal for dynamic reports. Unlike regular functions (e.g., =SUM), it automatically skips hidden rows, ensuring accurate totals after filtering. No special setup is required beyond having data in a table or range with headers.
What You'll Need
- A Microsoft Excel workbook (Excel 2010 or later, including Microsoft 365)
- Your data organized in a contiguous range with clear column headers (e.g., "Product", "Region", "Sales")
- At least one column containing numeric values to subtotal (e.g., sales amounts, quantities)
Step-by-Step
- Ensure your data has headers in the top row and no blank rows or columns within the dataset. Select any cell inside your data range.
- Go to the Data tab on the Excel ribbon.
- Click the Subtotal button in the Outline group. This opens the Subtotal dialog box.
- In the At each change in dropdown, select the column that defines your groups (e.g., "Region" if you want a subtotal for each region).
- In the Use function dropdown, choose the calculation type (e.g., Sum for totals, Average for means, Count for item counts).
- In the Add subtotal to list, check the box(es) for the column(s) you want to subtotal (e.g., check "Sales" to subtotal sales by region).
- Leave Replace current subtotals checked unless you’re adding to existing subtotals. Ensure Summary below data is selected for standard layout.
- Click OK. Excel inserts subtotal rows at each group change and displays the chosen function result.
- Use the outline symbols (gray numbers 1, 2, etc. on the left) to collapse or expand groupings. Clicking "1" shows only the grand total; "2" shows group totals; "3" shows all detail rows.
Common Mistakes
- Applying Subtotal to unsorted data: The command groups by changes in the "At each change in" column, so data must be sorted by that column first (e.g., sort by Region before adding Region subtotals).
- Subtotaling non-contiguous ranges: The tool only works on a single, continuous block of data. Gaps (blank rows/columns) cause incomplete grouping.
- Using regular SUM instead of SUBTOTAL: Manual =SUM formulas won’t ignore hidden rows when filtering; SUBTOTAL (function_num 109) is required for filtered data.
- Placing subtotals above data: If "Summary below data" is unchecked, totals appear above each group, which can confuse readers.
- Forgetting to clear old subtotals: Re-running Subtotal without checking "Replace current subtotals" duplicates calculations.
Tips
- Use Excel Tables (Ctrl+T) for dynamic ranges. Subtotals auto-adjust when you add/remove rows.
- For dynamic filtering without permanent subtotals, use =SUBTOTAL(109, range) directly in a cell—e.g., =SUBTOTAL(109, C2:C100) sums only visible cells in C2:C100 after filtering.
- Function numbers matter: 9–11 (SUM, AVERAGE, COUNT) include hidden rows; 109–111 ignore them. Use 109 for filtered reports.
- Remove subtotals cleanly: Select any cell, go to Data > Subtotal, then click Remove All.
- Combine with PivotTables for complex analyses. PivotTables offer more flexibility but Subtotal is faster for simple summaries.
Troubleshooting
If subtotals don’t appear or behave unexpectedly:
- No outline symbols appear: Ensure your data has no blank rows. Insert a blank row between groups manually if needed, or fix sorting.
- Incorrect totals: Verify data is sorted by the "At each change in" column before running Subtotal. Also, confirm the correct column is checked in "Add subtotal to".
- Subtotal ignores filters: You likely used =SUM or SUBTOTAL with function numbers 1–11. Replace with 109 (for SUM) or 101 (for AVERAGE) to exclude hidden rows.
- "Remove All" doesn’t work: The Subtotal dialog may be open. Close it, select a cell outside subtotals, then re-open Data > Subtotal > Remove All.
- Formula errors (#DIV/0!, #NAME?): Check for non-numeric data in the subtotal column. Text values cause SUM to return 0; use COUNTA for text counts.