To enter a subtotal formula in Excel, use the syntax =SUBTOTAL(function_num, ref1, [ref2], ...). Unlike the standard SUM function, the SUBTOTAL function allows you to calculate totals for a filtered list, meaning it only includes the rows that are currently visible on your screen, ignoring any data hidden by a filter. This makes it the essential tool for creating dynamic reports where the totals update automatically as you change your filter criteria.
What You'll Need
- A computer with Microsoft Excel installed (works across Windows and macOS).
- A dataset containing a column of numbers you wish to total.
- A basic understanding of how to select cell ranges in a spreadsheet.
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. For the SUBTOTAL function to work most effectively, your data should be contiguous, meaning there are no entirely empty rows or columns breaking up the dataset.
- Apply a Filter: Click anywhere inside your data range. Go to the Data tab on the ribbon and click the Filter button. You will see drop-down arrows appear in your header row. This step is crucial because the primary benefit of SUBTOTAL is its ability to react to these filters.
- Select the Target Cell: Click the cell where you want the subtotal to appear. It is common practice to place this cell either directly above the data headers or at the very bottom of the column. Placing it above the data is often more practical, as it remains visible even when you filter out thousands of rows.
- Start the Formula: Type
=SUBTOTAL(into the cell. This opens the function and prepares Excel to receive the two required arguments: the function number and the range. - Choose Your Function Number: Inside the parentheses, enter a number that tells Excel which calculation to perform. For a standard sum, enter
9(or109to ignore manually hidden rows). For an average, enter1(or101). After typing the number, add a comma to move to the next argument. For example, for a sum of visible cells, your formula currently looks like=SUBTOTAL(9,. - Select the Data Range: While the cursor is still inside the formula, click and drag your mouse to highlight the cells in the column you want to calculate. Alternatively, you can type the range manually (e.g.,
B2:B500). - Close and Execute: Type a closing parenthesis
)and press Enter. Your subtotal is now active. - Test the Dynamic Total: Click the filter arrow in one of your header columns and uncheck a few items. Notice that the subtotal value changes instantly to reflect only the rows that remain visible.
Common Mistakes
One of the most frequent errors is using the standard =SUM() function instead of =SUBTOTAL(). Users often find that their totals remain the same even after they filter the list, leading them to believe the filter isn't working. Remember that SUM adds every cell in the range regardless of visibility; only SUBTOTAL respects the filter.
Another common mistake is including the subtotal cell itself within the range of the formula. This creates a circular reference error because the cell is trying to calculate a sum that includes its own value, leading to an infinite loop. Always ensure your range starts and ends outside the cell containing the formula.
Users also frequently confuse the function numbers. Entering a 1 when you wanted a sum will result in an average, which may look like a wrong number if you aren't paying attention to the function code. Always double-check the function number against the official Excel list before pressing enter.
Finally, some users attempt to use SUBTOTAL on data that is not in a table or filterable list. While the formula will still work, you lose the primary advantage of the function. If you aren't using filters or hiding rows, a standard SUM is simpler and more efficient.
Tips
To make your spreadsheets more professional, use the 100-series function numbers (e.g., 109 instead of 9). The difference is subtle but important: the 1-11 series ignores rows hidden by a filter, but it still counts rows that you have manually hidden (by right-clicking a row and selecting Hide). The 101-111 series ignores both filtered-out rows and manually hidden rows. If you do a lot of manual row management, the 100-series is the safer bet.
For those working with massive datasets, consider converting your data range into an official Excel Table (Ctrl + T). When you do this, you can enable a "Total Row" via the Table Design tab. Excel automatically inserts the SUBTOTAL function into this row, saving you from typing the formula manually and ensuring the range expands automatically as you add new rows of data.
Combine SUBTOTAL with a "Helper Column" for complex reporting. If you need to subtotal based on multiple criteria that filters cannot easily handle, create a column that marks rows with a 1 or 0, and then filter for the 1s to let the SUBTOTAL formula do the heavy lifting.
Troubleshooting
If your SUBTOTAL formula returns a #VALUE! error, check for non-numeric data within your selected range. While SUBTOTAL generally ignores text, certain types of errors (like #N/A or #DIV/0!) existing within the source data will cause the subtotal formula to fail. You must fix the errors in the source cells first.
If the total is not changing when you filter your data, check to see if you accidentally used =SUM() instead of =SUBTOTAL(). If you are definitely using SUBTOTAL, ensure that you are using the Filter tool from the Data tab rather than simply hiding rows manually. If you are hiding rows manually, remember to use the 100-series function numbers (like 109) instead of the single-digit numbers.
If you see a circular reference warning, your formula range is too wide. For example, if your formula is in cell B1 and your range is B1:B100, the formula is trying to add itself. Change the range to B2:B100 to resolve this.
If the result is 0 but you can see numbers in the column, check the formatting of your source data. Often, numbers are formatted as "Text," which Excel cannot sum. You can fix this by selecting the column, going to the Home tab, and changing the number format dropdown from "Text" to "Number" or "General." You may need to double-click into the cells or use the "Text to Columns" feature to force Excel to recognize the change.
Frequently Asked Questions
What is the difference between SUBTOTAL and SUM?
SUM adds every cell in a specified range regardless of whether the row is hidden or filtered. SUBTOTAL only adds the cells that are visible after a filter has been applied, making it dynamic for reporting.
Which function number should I use for a total sum?
Use 9 if you only want to ignore rows hidden by a filter. Use 109 if you want to ignore both filtered rows and rows that you have manually hidden via the right-click menu.
Can SUBTOTAL be used for things other than adding?
Yes. By changing the first number in the formula, you can perform other calculations. For example, 1 is for Average, 2 is for Count (numbers), 3 is for CountA (non-empty cells), and 4 is for Maximum.
Does SUBTOTAL work in Google Sheets?
Yes, Google Sheets supports the SUBTOTAL function using the same syntax and function numbers as Microsoft Excel.
Why is my SUBTOTAL formula not updating automatically?
Ensure that your calculation options are set to "Automatic." Go to Formulas > Calculation Options and make sure Automatic is selected. If it is set to "Manual," you must press F9 to refresh the calculations.
Can I nest SUBTOTAL functions inside each other?
No, but you don't need to. The SUBTOTAL function is designed to ignore other SUBTOTAL formulas that are located within its range. This prevents "double counting" when you have multiple sub-totals and one grand total at the bottom.