The SUBTOTAL function in Excel calculates aggregated values like sum, average, or count for visible rows in a filtered list, ignoring hidden rows—making it ideal for dynamic data analysis. Unlike SUM or AVERAGE, SUBTOTAL automatically excludes rows hidden by filters, so your totals update correctly when you filter data. No special setup is needed beyond having numeric data in columns and enabling filtering.
What You'll Need
- A spreadsheet with numeric data in at least one column
- Excel with filtering enabled (available in all modern versions)
- A blank cell where you want the subtotal to appear
Step-by-Step
- Ensure your data has headers in the first row. For example, label column A as "Product", column B as "Sales", and column C as "Region". This helps Excel recognize your data range correctly when filtering.
- Select any cell within your data range. Go to the Data tab on the Ribbon, then click Filter. This adds dropdown arrows to each header cell. If you don’t see the Filter button, check that your data is formatted as a table or that you’ve selected a contiguous range with no blank rows or columns.
- Click the dropdown arrow in the header of the column you want to filter (e.g., "Region"). Uncheck "Select All" and then check only the values you want to include (e.g., "North" and "South"). Click OK. This hides rows that don’t match your criteria.
- Click on an empty cell below your data range, preferably in the same column as the numbers you want to subtotal. For example, if your sales figures are in column B, click in cell B100 or another cell below the last data row.
- Begin typing the formula: =SUBTOTAL(
- Enter the function number that corresponds to the calculation you need. For sum, use 9; for average, use 1; for count, use 2. For example, to sum visible sales figures, type 9.
- Now open a parenthesis and select the range of cells you want to subtotal. For example, if your sales data is in cells B2 to B80, click and drag from B2 to B80. Your formula should now read: =SUBTOTAL(9,B2:B80)
- Press Enter. Excel calculates the sum of only the visible rows in that range, ignoring any hidden by your filter.
- Test the formula by changing your filter. For example, uncheck "North" and check only "West". The subtotal will update automatically to reflect only the visible rows.
Common Mistakes
- Using SUM instead of SUBTOTAL: If you use SUM, it will include hidden rows and give incorrect totals when filters are applied.
- Using the wrong function number: Function number 109 sums visible rows, while 9 also includes manually hidden rows (not filtered). Use 109 if you want to ignore both filtered and manually hidden rows.
- Selecting the wrong range: Including header rows or blank cells in the range can cause errors or unexpected results. Always select from the first data cell to the last, excluding headers.
- Forgetting to enable filtering: Without filters, SUBTOTAL behaves like SUM because no rows are hidden. The benefit of SUBTOTAL only becomes visible when you apply filters.
- Typing the function number as text: You must enter 9, not "9" or "sum". Excel requires a numeric code, not a description.
Tips
- Use SUBTOTAL with structured tables: Convert your data range to a table (Ctrl+T) and SUBTOTAL will auto-adjust the range when you add new rows.
- Remember the function numbers: 9 and 109 are for sum; 1 and 101 for average; 2 and 102 for count numbers; 3 and 103 for count all; 4 and 104 for max; 5 and 105 for min. The 100-series ignores manually hidden rows; the 1-9 series does not.
- Combine with PivotTables for advanced analysis: SUBTOTAL works well alongside PivotTables, but they serve different purposes—SUBTOTAL is for filtered lists, PivotTables for dynamic grouping.
- Use absolute references if copying the formula: If you copy the SUBTOTAL formula across columns, use $B$2:$B$80 to lock the range so it doesn’t shift.
- Check for merged cells: Merged cells in your data range can interfere with filtering and SUBTOTAL accuracy. Unmerge them before applying filters.
Troubleshooting
- If the subtotal doesn’t update when you filter: Make sure you’re using SUBTOTAL and not SUM. Also, ensure the range includes only numeric data. Text in the range won’t break the formula but won’t be counted in sum or average.
- If you get a #REF! error: The range you selected may have been deleted or moved. Re-select the correct range in the formula bar.
- If the result is zero when you expect a number: Check that the visible rows contain actual numbers, not text formatted as numbers. Use the VALUE function or re-enter the numbers if needed.
- If SUBTOTAL returns the same result as SUM: You haven’t hidden any rows with a filter. Apply a filter to see the difference. Also confirm you’re not manually hiding rows—use the 109 function instead of 9 if you want to ignore manual hiding.
- If the dropdown arrow is missing: Go to Data > Filter. If the option is grayed out, your data may have blank rows or columns breaking the range. Fill or delete them and re-select the data range.