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)
- 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.
- 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:1for AVERAGE,2for COUNT,3for COUNTA,4for MAX,5for MIN. If you use109instead of9, it also ignores manually hidden rows (rows hidden by right-clicking) in addition to filtered rows. - 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
- Select the cell directly below the column of numbers you want to total.
- Click the AutoSum button (Home tab > Editing group > AutoSum, or press Alt+= on Windows, Cmd+Shift+T on Mac).
- 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. - 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.
- 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.
- Go to Data tab > Outline group > Subtotal.
- In the dialog, set At each change in to the grouping column (e.g., Region).
- Set Use function to Sum (or another function).
- Check the box for the column(s) you want to subtotal (e.g., Sales).
- Leave Replace current subtotals checked if you want to overwrite existing ones.
- Click OK. Excel inserts subtotal rows with
SUBTOTAL(9, ...)for each group, plus a grand total at the bottom. - 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 useSUBTOTALfor filtered data. - Wrong function number: Using
9for SUM is correct, but109also ignores manually hidden rows. Using2counts numbers only; use3for 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
SUBTOTALwith code 9 ignores them, but code 109 also ignores them. To include collapsed group subtotals in a grand total, you may need to useSUBTOTAL(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, notSUM. 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
- 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). - 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. - 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. - 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. - 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. - 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
- How to Add Subscript in Excel Cell (Windows & Mac)
- How to Add Subscript in Excel (3 Quick Ways)
- Data Entry Typing Speed: What Jobs Really Require
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- Google Sheets: Remove Dropdown from CellTo remove a dropdown from a cell in Google Sheets, select the cell (or range), go to Data…
- Google Sheets Day of Week: Formula and ExamplesTo get a day-of-week number in Google Sheets, use WEEKDAY; for example, with a date in A2 and…
- Why Is Maya Not Importing FBX? Fixes & CausesMaya fails to import an FBX file for one of several specific reasons: the FBX version is newer…
- Embed Video in PowerPoint and Play It AutomaticallyYes. In PowerPoint for Microsoft 365, select the video, open the Playback tab, and set Start to Automatically.…
- Split Text and Numbers in Excel: A Step-by-Step GuideTo split letters and digits from the same Excel cell, put the mixed value in A2, then use…
- How to Extract a Filtered List in ExcelTo extract matching rows in Excel, turn on filtering with Data > Filter, apply your criteria, then copy…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.