Referencing Filtered Data in Excel Using the SUBTOTAL Function

📅 Apr 04, 2026 📝 Sarah Miller

Managing complex spreadsheets is often frustrating when standard formulas aggregate hidden, filtered rows, skewing your reporting accuracy. While tracking standard funding sources typically requires rigid, static ledgers, leveraging the Excel SUBTOTAL function grants analysts the flexibility of dynamic, real-time visibility.

The primary stipulation is selecting the correct function number-specifically 109-to ensure hidden values are excluded during budget evaluations for allocations like federal research grants. Below, we outline the step-by-step formula construction to ensure your filtered data reporting remains flawless.

Referencing Filtered Data in Excel Using the SUBTOTAL Function

Excel is an indispensable tool for data analysis, but anyone who has worked with large datasets knows the frustration of dealing with filtered data. You apply a filter to narrow down your list to a specific region, product, or date range, and then you try to sum or average the results. If you use standard formulas like SUM, AVERAGE, or COUNT, you quickly notice a problem: Excel calculates the hidden rows along with the visible ones.

To reference only the visible, filtered data, you need to use the SUBTOTAL function. This versatile function is specifically designed to ignore rows that have been excluded by a filter, allowing you to build dynamic reports that update automatically as users filter your datasets. In this comprehensive guide, we will explore how to write Excel formulas to reference filtered data using SUBTOTAL, from basic setups to advanced, nested formulas.

Understanding the SUBTOTAL Function

The SUBTOTAL function is unique because it isn't just one mathematical operation; it is a gateway to 11 different functions. Its syntax is as follows:

=SUBTOTAL(function_num, ref1, [ref2], ...)
  • function_num: A number from 1 to 11 (or 101 to 111) that specifies which function to use for the subtotal (e.g., Sum, Average, Count).
  • ref1, ref2, ...: The ranges or cells you want to subtotal.

The Difference Between 1-11 and 101-111

The behavior of the SUBTOTAL function changes depending on the function number you choose. The function numbers are grouped into two sets:

Function Num (Includes Hidden Rows) Function Num (Ignores Hidden Rows) Equivalent Function
1101AVERAGE
2102COUNT
3103COUNTA
4104MAX
5105MIN
9109SUM

Crucial Distinction: Both the 1-11 series and the 101-111 series automatically ignore rows hidden by an Autofilter. The only difference lies in how they handle rows that you have manually hidden (by right-clicking a row and selecting "Hide").

  • Use 9 (or any 1-11 number) if you want to include manually hidden rows but exclude filtered-out rows.
  • Use 109 (or any 101-111 number) if you want to exclude both filtered-out rows and manually hidden rows.

Basic Examples of SUBTOTAL with Filtered Data

Let's look at a practical scenario. Suppose you have a sales dataset spanning from row 2 to row 100, where Column C contains the sales figures. You have applied a filter to Column B (Region) to show only "North America".

1. Summing Filtered Data

To find the sum of only the visible sales figures, use:

=SUBTOTAL(9, C2:C100)

As you change your filter to "Europe" or "Asia", this formula dynamically recalculates, displaying the sum of the visible rows only.

2. Counting Filtered Text Entries

If you want to count how many transactions are currently visible, use the COUNTA equivalent (function number 3 or 103):

=SUBTOTAL(3, B2:B100)

Advanced Technique: Dynamic Row Numbering for Filtered Lists

Have you ever filtered a list and noticed that the row numbers on the far left of Excel jump around (e.g., 2, 5, 12, 19)? If you want a column in your sheet that displays a clean, sequential list of numbers (1, 2, 3, 4...) regardless of how the data is filtered, you can use SUBTOTAL.

Assuming your data starts in Row 2, enter the following formula in cell A2 and drag it down:

=SUBTOTAL(3, $B$2:B2)

How it works: The COUNTA variation of SUBTOTAL looks at the range from the absolute anchor $B$2 down to the current row. Because SUBTOTAL ignores filtered-out rows, it only counts the visible cells above the current row, resulting in a perfect sequential list of numbers that updates on the fly as filters are applied.

Conditional Calculations on Filtered Data (SUMIF/COUNTIF on Filtered Rows)

One of the limitations of the SUBTOTAL function is that it cannot perform conditional calculations like SUMIF or COUNTIF on its own. For example, what if you want to sum sales over $5,000, but only for the rows currently visible after filtering?

To achieve this, we have to combine SUMPRODUCT, SUBTOTAL, OFFSET, and ROW. This is a classic, highly powerful Excel workaround.

The Formula Structure

To sum values in range C2:C100 where the values are greater than 5000, looking only at filtered rows, use:

=SUMPRODUCT((C2:C100>5000)*(SUBTOTAL(103, OFFSET(C2, ROW(C2:C100)-MIN(ROW(C2:C100)), 0, 1))))

How This Formula Works Under the Hood:

  1. ROW(C2:C100)-MIN(ROW(C2:C100)): This generates an array of sequential numbers starting from 0 (e.g., {0; 1; 2; 3; ...; 98}).
  2. OFFSET(C2, ..., 0, 1): This takes cell C2 and offsets it by each number in the array, one by one. This effectively breaks down the large range C2:C100 into an array of individual, single-cell references: {C2; C3; C4; ...; C100}.
  3. SUBTOTAL(103, ...): This evaluates each single-cell reference individually. If the cell is visible, it returns 1. If the cell is filtered out or hidden, it returns 0. This creates an array of 1s and 0s indicating visibility.
  4. (C2:C100>5000): This evaluates our criteria, returning TRUE (which equals 1) or FALSE (which equals 0) for each row.
  5. SUMPRODUCT: Finally, Excel multiplies the visibility array (1s and 0s) by the criteria array (1s and 0s) and sums up the resulting numbers. Only rows that are both visible and meet the criteria will yield a 1, giving you the correct filtered result.

The Modern Alternative: The AGGREGATE Function

If you are using Excel 2010 or later, Microsoft introduced an even more powerful function called AGGREGATE. While SUBTOTAL is excellent, AGGREGATE allows you to perform similar operations while also ignoring error values (like #N/A or #DIV/0!) in your calculations.

The syntax for AGGREGATE is:

=AGGREGATE(function_num, options, ref1, [ref2], ...)

To sum filtered data while ignoring any errors in the range, you can use:

=AGGREGATE(9, 7, C2:C100)

In this formula:

  • 9: Represents the SUM function.
  • 7: Is the option code to "Ignore hidden rows and error values".

This is highly recommended if your data source is messy or contains incomplete data that might throw off standard SUBTOTAL formulas.

Summary of Best Practices

  • Use Excel Tables (Ctrl + T): When your data is formatted as an official Excel Table, your formulas can use structured references (e.g., =SUBTOTAL(9, Table1[Sales])). This ensures that if you add new rows to your data, they are automatically included in your SUBTOTAL calculations.
  • Keep SUBTOTAL formulas outside the data range: Always place your SUBTOTAL formulas in a row above your table headers or far below your data. Placing them within the same columns as your data can cause circular reference errors or lead to the formula hiding itself when filters are applied.
  • Default to 100-series: Unless you have a specific reason to include manually hidden rows, default to using function numbers like 109 (SUM) and 103 (COUNTA) to ensure your calculations are perfectly aligned with what is visible on the screen.

By mastering the SUBTOTAL function and its advanced pairings with SUMPRODUCT or OFFSET, you can build truly dynamic, interactive, and error-free dashboards that react seamlessly to user inputs and filters.

Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.