The SUBTOTAL function in Excel 365 is used to perform calculations—such as summing, averaging, or counting—on a range of cells while ignoring rows that have been hidden by a filter. Unlike the standard SUM function, which adds every cell in a range regardless of whether it is visible, SUBTOTAL dynamically updates its result to reflect only the data currently displayed on your screen. This makes it the essential tool for creating interactive reports and dashboards where the user needs to toggle filters to see specific subsets of data.
What You'll Need
- Microsoft Excel 365 (Desktop or Web version).
- A dataset organized in a table or a range with clear column headers.
- The Filter feature enabled on your data range (Data tab > Filter).
Step-by-Step
- Prepare Your Data Range: Ensure your data is organized in a clean tabular format. Each column should have a unique header, and there should be no completely empty rows or columns within the dataset. If your data is not already a formal Excel Table, select your range and press Ctrl + T to convert it into a Table; this ensures the SUBTOTAL formula expands automatically as you add new rows.
- Insert a Total Row: Navigate to the cell where you want the subtotal to appear. It is standard practice to place this either directly above your headers or at the very bottom of your data range. If you are using a formal Excel Table, you can simply go to the Table Design tab and check the box for Total Row, which automatically inserts a SUBTOTAL function at the bottom.
- Enter the Function Syntax: Type
=SUBTOTAL(into the cell. The formula requires two arguments: the function_num and the ref1 (the range of cells). - Choose Your Function Number: The first argument is a number from 1 to 11 (or 101 to 111) that tells Excel which operation to perform. For example, if you want to sum the values, use 9 or 109. If you want to count the values, use 2 or 102. If you want the average, use 1 or 101.
- Select the Data Range: After the comma following the function number, highlight the range of cells you wish to calculate. For example, if your sales figures are in cells B2 through B100, your formula would look like
=SUBTOTAL(9, B2:B100). - Close the Formula and Press Enter: Close the parenthesis and press Enter. The cell will now display the total for the entire range.
- Apply Filters to Test: Go to the Data tab and click Filter. Use the drop-down arrows in your column headers to filter out specific categories. You will notice that the SUBTOTAL value changes instantly to reflect only the visible rows, whereas a standard SUM formula would remain static.
Common Mistakes
One of the most frequent errors is using the standard SUM function instead of SUBTOTAL when working with filtered lists. Users often find that their totals are "wrong" because the SUM function continues to calculate values in hidden rows, leading to inflated numbers that do not match the visible data.
Another common mistake is placing the SUBTOTAL formula inside the range it is calculating. This creates a circular reference error, as the formula is trying to calculate itself. Always place the subtotal either above the data range or sufficiently below it, ensuring the range reference (e.g., B2:B100) does not include the cell where the formula resides.
Users also frequently confuse the function numbers. Entering a 1 when they intended a 9 will result in an average instead of a sum. It is helpful to keep a cheat sheet of the function numbers nearby or use the formula autocomplete tool in Excel to verify the argument order.
Finally, some users forget that SUBTOTAL only ignores rows hidden by a filter, not rows hidden manually by right-clicking and selecting "Hide". To ignore manually hidden rows, you must use the 100-series function numbers (e.g., 109 instead of 9).
Tips
To make your spreadsheets more professional, combine SUBTOTAL with the AGGREGATE function. While SUBTOTAL is great for filters, AGGREGATE can ignore not only hidden rows but also error values (like #N/A or #DIV/0!), preventing your entire total from breaking just because one cell has an error.
If you are using a formal Excel Table (Ctrl + T), utilize the built-in Total Row. This feature allows you to change the calculation (Sum, Average, Count) via a simple drop-down menu in the total cell, removing the need to manually type function numbers into the formula bar.
For complex reports, use the SUBTOTAL function in a "Header Summary" area at the top of the page. By freezing the top rows (View > Freeze Panes > Freeze Top Row), you can keep your totals visible at all times, even as you scroll down through thousands of rows of filtered data.
If you need to subtotal multiple columns, you can write the formula for the first column and then drag the fill handle (the small square at the bottom-right of the cell) across to the right. Excel will automatically adjust the range references for the subsequent columns.
Troubleshooting
The total is not changing when I filter: First, check if you used the SUM function instead of the SUBTOTAL function. If you are using SUBTOTAL, ensure that you are using the Filter tool (Data > Filter) and not manually hiding rows. If you manually hid the rows, you must change your function number from 9 to 109.
I am getting a #VALUE! error: This usually happens if the range you selected contains non-numeric data that the specific function cannot handle. Check for text strings or spaces being treated as text within your numeric columns. Ensure the range reference is accurate and does not include the header row if you are using a function that requires strictly numeric input.
The result is 0 even though there is data: Verify that your numbers are actually stored as numbers. Sometimes data imported from web sources or CSVs is stored as text. You can tell if there is a small green triangle in the corner of the cell. Select the cells, click the warning icon, and choose "Convert to Number".
Circular Reference Warning: If Excel warns you of a circular reference, your formula is likely including its own cell in the range. For example, if your formula is in cell B101 and your range is B2:B101, the formula is trying to add itself. Change the range to B2:B100.
Frequently Asked Questions
What is the difference between function 9 and 109?
Function 9 ignores rows hidden by a filter, but it includes rows that were hidden manually (by right-clicking the row and selecting Hide). Function 109 ignores both filtered-out rows and manually hidden rows.
Can SUBTOTAL be used for counting text?
Yes. Use function number 3 (or 103) to perform a COUNTA operation, which counts cells that are not empty, regardless of whether they contain text or numbers, while still respecting your filters.
Does SUBTOTAL work with Pivot Tables?
No, SUBTOTAL is designed for standard ranges and Tables. Pivot Tables have their own built-in aggregation methods (Sum, Count, Average) that automatically update when you use Slicers or Pivot Filters.
Can I nest a SUBTOTAL inside another formula?
Yes, you can use SUBTOTAL as an argument within other functions, such as using it inside an IF statement to trigger a warning if the visible total exceeds a certain budget threshold.
Will SUBTOTAL slow down my workbook?
In most cases, no. However, if you have tens of thousands of SUBTOTAL formulas across a massive workbook, you may notice a slight lag during filtering as Excel must recalculate every visible instance. For extremely large datasets, consider using Power Pivot.