The SUBTOTAL function in Excel allows you 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 or AVERAGE functions, which calculate every cell in a range regardless of visibility, SUBTOTAL dynamically updates its result to reflect only the data currently visible on your screen. This makes it the essential tool for creating interactive reports and dashboards where users frequently filter data to see specific subsets of information.

What You'll Need

  • Microsoft Excel (any modern version including Office 365, 2021, 2019, or Excel for the Web).
  • A dataset organized in a table or a range with clear column headers.
  • Data that is either already filtered or intended to be filtered using the Filter tool (Data tab > Filter).

Step-by-Step

  1. Prepare Your Data: Ensure your data is organized in a continuous block with no entirely empty rows or columns. For the best results, select your data range and press Ctrl + T to convert it into an official Excel Table. This ensures that as you add new rows, your SUBTOTAL formula will automatically expand to include them.
  2. Position Your Formula: Click into the cell where you want the result to appear. It is highly recommended to place the SUBTOTAL formula above your data headers rather than below the data. If you place it at the bottom, the formula cell itself might be hidden when you apply a filter, making the result invisible.
  3. Start the Formula: Type =SUBTOTAL( into the cell.
  4. Select the Function Number: The first argument of the SUBTOTAL function is a number (1-11 or 101-111) that tells Excel which calculation to perform. For example, if you want to sum the visible values, type 9 or 109. Common function numbers include:
    • 1 or 101: AVERAGE
    • 2 or 102: COUNT (counts numbers)
    • 3 or 103: COUNTA (counts non-empty cells)
    • 4 or 104: MAX
    • 5 or 105: MIN
    • 9 or 109: SUM
  5. Define the Range: After the function number, type a comma and then select the range of cells you want to calculate. For example, if your sales figures are in column B from row 5 to 100, your formula would look like =SUBTOTAL(9, B5:B100).
  6. Close and Execute: Type the closing parenthesis ) and press Enter.
  7. Test the Filter: Go to the Data tab and click Filter. Use the dropdown arrows in your column headers to filter out some of your data. Notice that the value in your SUBTOTAL cell changes instantly to reflect only the rows remaining on the screen.

Common Mistakes

One of the most frequent errors is using the standard SUM function instead of SUBTOTAL when working with filtered lists. If you use =SUM(B5:B100), Excel will continue to add up every single cell in that range, even if 90% of the rows are hidden by a filter. This leads to misleading reports where the total does not match the visible data.

Another common mistake is placing the SUBTOTAL formula directly beneath the data range without using an Excel Table. When you apply a filter to the headers, Excel often hides any row that doesn't match the criteria. If your total is in row 101 and row 101 doesn't meet the filter criteria, your total disappears. Always place totals at the top or use the built-in "Total Row" feature of an Excel Table (Table Design tab > Total Row).

Users also frequently confuse the function numbers. Using 2 (COUNT) when they intended to use 3 (COUNTA) will result in a total of 0 if the column contains text (like names) instead of numbers. Always verify whether you are counting numeric values or any non-blank cell.

Tips

Understanding 9 vs 109: You may have noticed two sets of numbers for each function. The numbers 1-11 ignore rows hidden by filters, but they still include rows that you have hidden manually (by right-clicking a row and selecting Hide). The numbers 101-111 ignore both filtered-out rows AND manually hidden rows. If you frequently hide rows by hand to clean up your view, use the 100-series codes (e.g., 109 for SUM) to ensure your totals are strictly based on what is visible.

Combining with Tables: When you convert a range to a Table (Ctrl + T), you can use structured references. Instead of B5:B100, your formula might look like =SUBTOTAL(9, [Sales]). This is far more powerful because if you add 50 more rows of data, the formula updates automatically without you having to change the cell range manually.

Using the AutoSum Shortcut: If you have an Excel Table and enable the "Total Row" in the Table Design tab, Excel automatically inserts a SUBTOTAL function into the bottom row. You can change the calculation (Sum, Average, Count) simply by clicking the dropdown arrow that appears in the total cell.

Troubleshooting

If your SUBTOTAL formula is returning a #VALUE! error, check for non-numeric data within your range. While SUBTOTAL is generally good at ignoring text when summing, certain data types or errors within the cells themselves (like #REF! or #N/A) will cause the SUBTOTAL function to fail. Use the IFERROR function to clean your source data first.

If the result is not changing when you filter, ensure you are actually using a Filter (Data > Filter) and not just hiding rows manually. If you are hiding rows manually and using function code 9, the value will not change. Switch to function code 109 to fix this.

If the formula returns 0 unexpectedly, verify the data type of your numbers. Sometimes numbers are imported as text. You can tell if this is happening if there is a small green triangle in the corner of the cell. Select the cells, click the warning icon, and select "Convert to Number." Only then will the SUBTOTAL function be able to calculate the sum.

Frequently Asked Questions

Can SUBTOTAL be used for multiple columns?

Yes, you can include multiple ranges in a single formula by separating them with commas, such as =SUBTOTAL(9, B5:B100, D5:D100). However, it is usually cleaner to have a separate subtotal for each column.

Does SUBTOTAL work with Pivot Tables?

No, SUBTOTAL is designed for raw data ranges and Tables. Pivot Tables have their own built-in summarization tools (Sum, Count, Average) that are handled via the Value Field Settings, which automatically adjust as you slice and dice the data.

Why is my SUBTOTAL result different from my SUM result?

This happens because a filter is active. The SUM function calculates every cell in the range, while the SUBTOTAL function only calculates the cells that are currently visible. If the results differ, it means some rows are hidden.

Can I nest SUBTOTAL functions inside each other?

No, Excel is designed to ignore other SUBTOTAL formulas within the range it is calculating. This is actually a feature: it prevents "double counting" if you have subtotals for different categories and then a grand total at the bottom.

Is there a limit to how many rows SUBTOTAL can handle?

The limit is the same as any other Excel formula—it can handle as many rows as exist in the worksheet (up to 1,048,576 rows). However, very large ranges may slightly slow down calculation speed when filtering.