How to Add Subtotal to Filtered Data in Excel

How-to basics · Updated November 27, 2026

When you filter a list in Excel, the normal SUBTOTAL function is the only way to get sums, averages, or counts that ignore hidden rows. This guide shows you how to add a subtotal to filtered data using the SUBTOTAL function, the AutoSum button, and the Subtotal command—plus how to make the total update automatically when you change filters. You’ll need a worksheet with data in a table or a range, and a basic understanding of Excel formulas.

What You’ll Need

  • Excel for Microsoft 365, Excel 2021, Excel 2019, or Excel 2016 (steps are similar for Mac and Excel for the web).
  • A dataset with column headers and no entirely blank rows or columns.
  • Familiarity with filtering (using the filter arrows in the header row).

Step-by-Step

Method 1: Use the SUBTOTAL Function (Recommended)

  1. Select the cell where you want the subtotal to appear. Usually this is directly below the last data row, but it can be anywhere outside the filtered range.
  2. Type the formula. With your data in, say, A1:C100 and the numeric column you want to sum in column C, enter:
    =SUBTOTAL(9, C2:C100)
    The first argument, 9, means SUM. Other common codes: 1 for AVERAGE, 2 for COUNT, 3 for COUNTA, 4 for MAX, 5 for MIN. If you use 109 instead of 9, it also ignores manually hidden rows (rows hidden by right-clicking) in addition to filtered rows.
  3. Press Enter. The cell shows the sum of only the visible (filtered) rows. When you change or clear the filter, the result updates automatically.

Method 2: Use AutoSum with Filter

  1. Select the cell directly below the column of numbers you want to total.
  2. Click the AutoSum button (Home tab > Editing group > AutoSum, or press Alt+= on Windows, Cmd+Shift+T on Mac).
  3. Excel inserts =SUBTOTAL(9, range) automatically, but only if the data is in a filtered list or an Excel Table. If it inserts =SUM(...) instead, replace it with =SUBTOTAL(9, ...) manually.
  4. Press Enter. The total now respects the filter.

Method 3: Use the Subtotal Command (for Grouped Data)

This method adds subtotals for each group in a sorted list, not just a single total. It is useful when you have categories in a column and want a subtotal per category, and it works with filtered data only if you filter after creating the subtotals.

  1. Sort your data by the column you want to group by (e.g., Region). Select any cell in the column and use Data > Sort A to Z or Z to A.
  2. Go to Data tab > Outline group > Subtotal.
  3. In the dialog, set At each change in to the grouping column (e.g., Region).
  4. Set Use function to Sum (or another function).
  5. Check the box for the column(s) you want to subtotal (e.g., Sales).
  6. Leave Replace current subtotals checked if you want to overwrite existing ones.
  7. Click OK. Excel inserts subtotal rows with SUBTOTAL(9, ...) for each group, plus a grand total at the bottom.
  8. Now you can apply a filter to the data. The subtotal rows will remain visible, and the grand total will adjust to show only the visible groups? Actually, the grand total from the Subtotal command uses SUBTOTAL(9, ...) over the entire range, so it will ignore hidden rows when you filter the list. Note: the per-group subtotals will also hide if their group rows are hidden by the filter.

Common Mistakes

  • Using SUM instead of SUBTOTAL: =SUM(A2:A100) adds all cells, even hidden ones. Always use SUBTOTAL for filtered data.
  • Wrong function number: Using 9 for SUM is correct, but 109 also ignores manually hidden rows. Using 2 counts numbers only; use 3 for non-empty cells.
  • Including the subtotal cell in the range: If your formula is in C101 and your range is C2:C101, you get a circular reference. Keep the range strictly to data cells.
  • Filtering after using the Subtotal command: If you filter before creating subtotals, the command may not work correctly because it expects all data to be visible. Sort and subtotal first, then filter.
  • Hidden rows from grouping: If you use the Subtotal command, it creates outline groups. Collapsing those groups hides rows, and SUBTOTAL with code 9 ignores them, but code 109 also ignores them. To include collapsed group subtotals in a grand total, you may need to use SUBTOTAL(109, ...) on the visible subtotal rows.

Tips

  • Use an Excel Table: Convert your range to a table (Ctrl+T or Cmd+T). Then the filter arrows are always visible, and any formula you enter in a cell outside the table will automatically use structured references. For example, =SUBTOTAL(109, Table1[Sales]).
  • Add a total row to a table: With a table selected, check the Total Row box in the Table Design tab. The total row uses SUBTOTAL(109, ...) automatically and updates with filters.
  • Use the status bar: For a quick check without formulas, select the filtered numbers and look at the status bar at the bottom of Excel—it shows the sum, average, and count of the selected cells.
  • Keyboard shortcut for AutoSum: Press Alt+= (Windows) or Cmd+Shift+T (Mac) to insert a SUBTOTAL formula quickly.
  • Copying the subtotal formula: If you copy a cell with SUBTOTAL, the range adjusts relative to the new location. Use absolute references (e.g., $C$2:$C$100) if you want it to stay fixed.

Troubleshooting

  • Subtotal shows 0 or #VALUE!: Check that the range contains numbers, not text. Also ensure the function number is correct (9 for SUM). If you see #VALUE!, the range may include non-numeric data; use SUBTOTAL(9, ...) on a numeric column only.
  • Total does not update when filter changes: Make sure the formula is actually SUBTOTAL, not SUM. Also, if you used the Subtotal command and then filtered, the grand total may not update if it was inserted as a static value? Actually, the Subtotal command inserts formulas, so they should update. If not, recalculate by pressing F9 (Windows) or Cmd+= (Mac).
  • Circular reference warning: This happens when the SUBTOTAL formula range includes the cell itself. Adjust the range to exclude the formula cell.
  • Subtotal command grayed out: The Subtotal command is only available when your data is in a normal range, not an Excel Table. Convert the table back to a range (Table Design > Tools > Convert to Range) or use the SUBTOTAL function manually.
  • Filter arrows missing: If you don’t see filter arrows, select your data and press Ctrl+Shift+L (Windows) or Cmd+Shift+F (Mac) to toggle filters, or use Data > Filter.

Frequently Asked Questions

  1. Why does my SUM formula not ignore hidden rows?
    Because SUM adds every cell in the range, regardless of visibility. SUBTOTAL is designed to ignore rows hidden by a filter (and optionally by manual hiding).
  2. What is the difference between SUBTOTAL(9) and SUBTOTAL(109)?
    Both sum visible filtered rows. Code 9 ignores rows hidden by a filter, but includes rows hidden manually (right-click > Hide). Code 109 ignores both filtered and manually hidden rows.
  3. Can I use SUBTOTAL with other functions like AVERAGE or COUNT?
    Yes. Use function numbers 1 (AVERAGE), 2 (COUNT), 3 (COUNTA), 4 (MAX), 5 (MIN), and their 100-series equivalents (101-105) for ignoring manually hidden rows.
  4. How do I add a subtotal to a filtered Excel Table?
    Enable the Total Row in the Table Design tab. The total row uses SUBTOTAL(109, …) automatically and updates with filters. You can change the function by clicking the total cell and selecting from the dropdown.
  5. Does the Subtotal command work with filters?
    Yes, but it’s best to apply the Subtotal command before filtering. The command inserts SUBTOTAL formulas that respect filters applied afterward. However, if you filter out a group, its subtotal row is hidden, and the grand total adjusts accordingly.
  6. Why is my SUBTOTAL formula showing the same as SUM?
    If no rows are hidden (no filter applied), SUBTOTAL and SUM return the same result. Apply a filter to see the difference. Also, check that you didn’t accidentally use code 9 instead of 109 when you meant to ignore manually hidden rows.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.