In Excel, the number 9 in a SUBTOTAL formula tells the program to calculate the sum of the selected range while ignoring rows that have been hidden by a filter. Unlike the standard SUM function, which adds up every cell in a range regardless of whether you can see them or not, SUBTOTAL(9, range) dynamically updates to only include the values currently visible on your screen after a filter has been applied.
This is an essential tool for data analysis because it allows you to filter a large dataset—for example, by a specific date, region, or category—and see an instant total for only those specific items without having to create a new table or use complex array formulas. It ensures that your totals remain accurate and relevant to the specific view you have active in your spreadsheet.
What You'll Need
- A computer with Microsoft Excel installed (works across all modern versions including Excel 365, 2021, 2019, and 2016).
- A dataset containing at least one column of numerical values.
- A table or range of data that has been formatted with filters (Data > Filter).
Step-by-Step
- Prepare Your Data: Ensure your data is organized in a clean table format with clear headers at the top of each column. Make sure there are no completely empty rows or columns within your data block, as this can sometimes confuse Excel's range detection.
- Apply Filters: Select your header row. Go to the Data tab on the top ribbon and click the Filter button. You will now see small drop-down arrows appearing in the corner of each header cell.
- Position Your Total Cell: Decide where you want the total to appear. It is highly recommended to place your SUBTOTAL formula above your data headers rather than below them. If you place it at the bottom, the formula cell itself might be hidden when you filter the data, making your total disappear from view.
- Enter the Formula: Click into the cell where you want the sum to appear. Type the following formula:
=SUBTOTAL(9, [range]). For example, if your numbers are in column B from row 5 to row 100, you would type=SUBTOTAL(9, B5:B100). - Confirm the Range: Press Enter. At this stage, since no filters are applied, the result will be identical to a standard SUM function.
- Filter Your Data: Click the drop-down arrow in one of your header columns. Uncheck the items you want to hide and click OK.
- Observe the Change: Notice that the value in your SUBTOTAL cell changes instantly. It is now only adding up the numbers in the rows that remain visible. If you clear the filter, the total will return to the sum of the entire range.
Common Mistakes
One of the most frequent errors is confusing the function number 9 with function number 109. While both perform a sum, they behave differently regarding manually hidden rows. Function 9 ignores rows hidden by a filter, but it still includes rows that you have hidden manually (by right-clicking a row and selecting Hide). Function 109 ignores both filtered-out rows and manually hidden rows. If you are using manual hiding instead of the Filter tool, using 9 will give you an inflated total.
Another common mistake is including the SUBTOTAL cell itself within the range of the formula. For example, if your formula is in cell B2 and you write =SUBTOTAL(9, B2:B100), you create a circular reference. This happens because the formula is trying to add itself into the total, which will cause Excel to display an error message or return a zero. Always ensure the formula cell is outside the range being summed.
Users also often forget that SUBTOTAL only works on numerical data. If your "numbers" are actually formatted as text (often indicated by a small green triangle in the corner of the cell), the SUBTOTAL function will ignore them, resulting in a total of 0 or a sum that is lower than expected. You must convert these cells to Number format for the formula to function correctly.
Tips
To make your spreadsheet more professional, combine the SUBTOTAL function with an Excel Table (Ctrl + T). When you convert a range into an official Table, you can enable a "Total Row" in the Table Design tab. Excel automatically uses the SUBTOTAL function for these rows, meaning you don't have to write the formula manually. This is the fastest way to implement this functionality.
If you need to perform different calculations besides summing, you can simply change the number 9 to another code. For instance, using 1 instead of 9 will give you the average of the visible cells, and using 2 will give you the count of visible cells. Keeping a small cheat sheet of these codes can help you build more powerful dashboards.
For very large datasets, consider using the SUBTOTAL function in conjunction with Slicers. Slicers are visual buttons that act as filters. When you click a Slicer button, the SUBTOTAL(9, ...) formula updates instantly, creating a dynamic report that feels like a professional application rather than a static spreadsheet.
Troubleshooting
The total isn't changing when I filter: First, check that you used the SUBTOTAL function and not the SUM function. SUM will always add everything, regardless of visibility. Second, verify that you are using a Filter (the drop-down arrows) and not just hiding rows manually. If you are hiding rows manually, you must change the 9 to 109.
The formula returns #VALUE!: This usually happens if there is an error within the range you are summing. If one of the cells in your range contains an error like #DIV/0! or #N/A, the SUBTOTAL function will pass that error through to the result. You will need to find the error in your data and fix it, or use the AGGREGATE function, which can be told to ignore error values.
The result is 0 even though I see numbers: Check the formatting of your numbers. Select the column, go to the Home tab, and change the format from "Text" to "Number" or "General." If the numbers were imported from a web source or a CSV, they might be stored as text. You may need to use the "Text to Columns" feature in the Data tab to force Excel to recognize them as numbers.
Frequently Asked Questions
What is the difference between SUBTOTAL(9, ...) and SUM()?
SUM adds every cell in the range regardless of visibility. SUBTOTAL(9, ...) only adds cells that are visible after a filter has been applied, making it dynamic.
Can I use SUBTOTAL for things other than summing?
Yes. By changing the first argument (the number), you can perform other tasks. For example, 1 is for Average, 2 is for Count, 3 is for Max, and 4 is for Min.
Why should I put the SUBTOTAL formula at the top of the sheet?
If the formula is at the bottom of your data, it may be hidden when you apply a filter to the rows above it. Placing it at the top ensures the total is always visible regardless of how much data is filtered out.
Does SUBTOTAL(9, ...) ignore manually hidden rows?
No. It only ignores rows hidden by a filter. To ignore rows that were hidden manually via the right-click menu, you must use the function code 109 instead of 9.
Will SUBTOTAL work if I have other SUBTOTAL formulas in the range?
Yes. One of the best features of the SUBTOTAL function is that it ignores other SUBTOTAL formulas within its range. This prevents "double counting" when you have nested totals in a large report.