How to Use SUBTOTAL in Excel by Category Step by Step
In this article
The Excel SUBTOTAL function calculates totals (like SUM, AVERAGE, COUNT) for filtered data while ignoring other SUBTOTAL results, making it ideal for category-based summaries in filtered lists. You need a structured table or range with clear category columns and data rows—no special add-ins required.
What You'll Need
- A properly formatted Excel table or data range (no blank rows/columns within the data)
- At least one column containing category names (e.g., "Product", "Region", "Department")
- At least one numeric column to subtotal (e.g., "Sales", "Quantity")
- Excel installed (any modern version: Microsoft 365, Excel 2021, 2019, 2016, or Excel Online)
Step-by-Step
- Organize your data: Ensure your dataset is in a contiguous block with headers in the first row. For example, columns A:C might be "Category", "Item", and "Amount". Remove any blank rows or columns inside the data area—SUBTOTAL can misbehave if rows are missing.
- Sort your data by category (optional but recommended): Though not required for SUBTOTAL itself, sorting helps readability. Select any cell in your data, go to the Data tab, click Sort, choose your category column (e.g., "Category"), and sort A to Z. This groups all entries for each category together.
- Insert a helper column for subtotals (if needed): If you want category-level subtotals *within* the same table, insert a new column next to your data (e.g., column D titled "Category Total"). This column will hold the SUBTOTAL formula referencing only the current category's rows.
- Apply the SUBTOTAL formula: In the first data row of your helper column (e.g., D2), enter:
=SUBTOTAL(9,C2)if column C contains numeric values. Here,9is the function code for SUM (use1for AVERAGE,3for COUNT, etc.). ReplaceC2with the cell containing the numeric value for that row. - Expand the formula to all rows: Double-click the small square at the bottom-right corner of cell D2 (the fill handle) to copy the formula down the entire column. Each row now shows the subtotal *for its category only*—but this alone won’t give grouped totals yet.
- Use AutoFilter to isolate categories: Go to the Data tab and click Filter (or press Ctrl+Shift+L). Click the dropdown arrow in the Category column, then select one category (e.g., "Electronics"). Only rows matching that category remain visible.
- Verify the subtotal updates: In any visible row for that category, check the SUBTOTAL result in the helper column. Because SUBTOTAL ignores hidden rows, the value shown *for each visible row* reflects the total for the entire category (e.g., all Electronics rows will display the same sum). This is the key behavior: the formula recalculates dynamically when you filter.
- Place a final summary (optional): For a clean report, add a new row below your data (e.g., row 100 if your data ends at row 99). In the numeric column (e.g., C100), enter
=SUBTOTAL(9,C2:C99). This gives the grand total for the entire filtered list, ignoring hidden rows and other SUBTOTAL results.
Common Mistakes
- Using SUM instead of SUBTOTAL: SUM includes hidden rows, so filtering won’t update totals. Always use SUBTOTAL when dynamic filtering is needed.
- Wrong function code: Using code
109(hidden-row-inclusive SUM) instead of9defeats the purpose. Stick with9(sum),101(average), etc., for hidden-row-excluding versions. - Non-contiguous ranges: SUBTOTAL works best with single-column references (e.g., C2:C99). Avoid referencing entire columns like C:C unless your data fills them—this can slow performance or cause errors.
- Nested SUBTOTALs: If you place SUBTOTAL formulas *within* the range they reference (e.g., =SUBTOTAL(9,D2:D10) where D5 itself contains =SUBTOTAL(...)), Excel ignores those nested SUBTOTALs, leading to double-counting. Keep formulas separate from the data range being summed.
Tips
- Keyboard shortcut for filtering: After sorting, press Alt+A+M+F to quickly apply AutoFilter to your data range.
- Convert to Excel Table: Select your data and press Ctrl+T, then check "Table has headers." Tables auto-expand SUBTOTAL formulas and make filtering more intuitive.
- Function code cheat sheet: Use
9for SUM,109for SUM ignoring hidden rows,1for AVERAGE,101for AVERAGE ignoring hidden rows,2for COUNT (numbers only),102for COUNT ignoring hidden rows. For category subtotals, prefer codes starting with1(e.g.,101) to exclude hidden rows explicitly. - Color-coding for clarity: Apply conditional formatting to the helper column—highlight rows where the SUBTOTAL value changes to visually group categories.
Troubleshooting
If your SUBTOTAL doesn’t update when filtering:
- Check for hidden rows outside your range: Ensure no rows above or below your data are hidden (e.g., row 100). Unhide all rows (right-click row numbers > Unhide).
- Verify the range in the formula: Confirm the formula references only the numeric data column (e.g., C2:C100, not C:C or B2:D100). A mixed range can cause #REF! errors or incorrect totals.
- Disable manual calculation: Go to Formulas > Calculation Options and ensure "Automatic" is selected. If "Manual" is checked, press F9 to force a recalculation.
- Check for text in numeric columns: SUBTOTAL ignores non-numeric cells. Use Filter to check for blank or text entries in your numeric column—clean them using Data > Text to Columns or a formula like =IF(ISNUMBER(C2),C2,0).
- Reset filters: Click Data > Clear to remove all filters, then reapply them. This refreshes hidden-row detection.
Frequently Asked Questions
Can SUBTOTAL handle multiple categories at once?
Not directly. SUBTOTAL works on filtered data, so you can filter by one category at a time. For multi-category summaries (e.g., Category + Subcategory), use a PivotTable instead—it’s designed for hierarchical grouping.
Does SUBTOTAL work with filtered tables?
Yes, and it’s ideal for them. When applied to Excel Tables (created with Ctrl+T), SUBTOTAL automatically adjusts its range as you add rows, and filtering the table hides rows correctly.
Why does my SUBTOTAL show the same value for every row?
That’s expected behavior for category-level subtotals: when filtered, every visible row in a category displays the same total. To see per-row values, unfilter the data or use a different approach like SUMIF.
Can I subtotal only visible rows after manual hiding?
Yes—use function codes starting with 1 (e.g., 109 for SUM, 101 for AVERAGE). Codes like 9 ignore *filtered* rows but include *manually hidden* rows; codes 100+ ignore both.
How do I subtotal by category without filtering each time?
Use SUMIF or SUMIFS instead. For example: =SUMIF($A:$A, $A2, $C:$C) sums all amounts in column C where column A matches the category in A2, regardless of filters.
Does SUBTOTAL work in Excel Online?
Yes, fully. The syntax and behavior are identical to desktop Excel, including filtering, formulas, and function codes.