The SUBTOTAL formula in Excel calculates aggregated values like sum, average, or count for visible rows only, ignoring hidden rows—ideal for filtered data. No special tools are needed; just Excel and a dataset with rows you may hide or filter.
What You'll Need
- Microsoft Excel (any version from 2007 onward)
- A table or range of data with numerical values
- Rows that may be filtered or manually hidden
Step-by-Step
- Open your Excel file and ensure your data is in a structured table format with headers. For example, column A might list product names, column B has sales figures, and column C has quantities.
- Select the cell where you want the subtotal to appear—typically just below your data range or in a summary row.
- Type the formula: =SUBTOTAL(
- After the opening parenthesis, enter a number that corresponds to the function you want. For sum, use 9; for average, use 1; for count, use 2. The most common is 9 for sum.
- After the number, add a comma, then select the range of cells you want to subtotal. For example, if your sales data is in cells B2 to B100, click and drag from B2 to B100.
- Close the formula with a closing parenthesis: ) and press Enter. Your formula should look like: =SUBTOTAL(9,B2:B100)
- Apply a filter to your data by selecting any cell in your table, then going to the Data tab and clicking Filter. Dropdown arrows will appear in your headers.
- Click the dropdown in any column (e.g., Product Name) and uncheck some items to hide rows. The subtotal will automatically update to include only the visible rows.
- Manually hide a row by right-clicking the row number (e.g., row 5) and selecting Hide. The subtotal will ignore it, confirming it works with both filters and manual hiding.
Common Mistakes
- Using 109 instead of 9 when you don’t need to ignore manually hidden rows—109 ignores both filtered and manually hidden rows, but 9 only ignores filtered ones. Use 9 for most cases.
- Forgetting the comma between the function number and the range, which causes a formula error.
- Selecting the entire column (e.g., B:B) instead of a specific range like B2:B100, which can slow down large files and include unintended data.
- Typing the formula manually without using the function wizard, leading to typos like SUBTOTAL(9, B2:B100) with extra spaces or incorrect cell references.
- Assuming SUBTOTAL works with manually hidden rows when using function numbers 1–11 instead of 101–111. Only numbers 101–111 ignore manually hidden rows.
Tips
- Use the function wizard: Click the Formulas tab > More Functions > Statistical > SUBTOTAL. This ensures correct syntax and helps you pick the right number.
- Use named ranges for easier reading. Select your data range, go to Formulas > Define Name, type "SalesData", then use =SUBTOTAL(9,SalesData).
- Combine SUBTOTAL with PivotTables for dynamic reporting. PivotTables auto-update with filters, but SUBTOTAL gives you control over exact calculations.
- If you're working in Hindi interface Excel, the function name may appear as "SUBTOTAL" in English—it doesn’t change. Excel uses English function names regardless of language settings.
- Always test your formula by hiding a few rows manually and confirming the subtotal changes. This verifies it’s working correctly.
- For large datasets, use Excel Tables (Insert > Table) so your range automatically expands when you add new rows, and SUBTOTAL will include them without adjustment.
Troubleshooting
- If the formula returns #NAME? error, Excel doesn’t recognize "SUBTOTAL". Check for typos like "Subtotal" or "Sub Total"—it must be spelled exactly as SUBTOTAL.
- If the result doesn’t change when you filter, ensure you didn’t use a function number from 1–11. Switch to 9 (for sum), 1 (for average), or 2 (for count). Numbers 1–11 include hidden rows.
- If the formula shows 0 but you expect a value, check if the selected range includes text or blank cells. SUBTOTAL ignores text but sums only numbers. Ensure your data column contains numeric values.
- If you’re using Excel on a Mac and the formula isn’t working, ensure you’re not in Manual Calculation mode. Go to Formulas > Calculation Options and select Automatic.
- If the filter dropdown disappears after applying SUBTOTAL, reapply the filter: select your header row, go to Data > Filter, and toggle it off then on again.
- For extremely large datasets, performance may slow. Limit the range to actual data (e.g., B2:B500 instead of B:B) to improve speed.
Frequently Asked Questions
Can I use SUBTOTAL with text data?
No, SUBTOTAL only works with numeric values. Functions like SUM, AVERAGE, COUNT, and COUNTA ignore text, but COUNTA counts non-blank cells including text. Use 3 for COUNTA to count visible non-blank cells.
What’s the difference between SUBTOTAL and SUM?
SUM adds all values in a range, even hidden or filtered rows. SUBTOTAL ignores filtered rows and can also ignore manually hidden rows depending on the function number used. SUBTOTAL is safer for dynamic data.
Why does my SUBTOTAL show the same number even after filtering?
You likely used a function number between 1 and 11. Change it to 101–111 to ignore manually hidden rows, or 9, 1, 2 for filtered rows. Use 9 for sum to ignore filtered rows only.
Can I use SUBTOTAL across multiple sheets?
No, SUBTOTAL cannot reference ranges across different sheets in one formula. You must use a helper column on each sheet or combine data into one sheet first.
Does SUBTOTAL work with conditional formatting?
Yes, but conditional formatting rules apply to the original cell values, not the subtotal result. The formatting won’t change based on whether a row is hidden or shown.
Is SUBTOTAL available in Excel Mobile?
Yes, SUBTOTAL works in Excel Mobile for iOS and Android, but the interface is simplified. Enter the formula manually or use the function picker under the Formulas tab if available.