How to Sum and Aggregate Only Visible Cells in Filtered Excel Rows

📅 Feb 05, 2026 📝 Sarah Miller

Filtering data in Excel only to find your formulas still calculate hidden rows is incredibly frustrating. While standard functions like SUM or AVERAGE are the go-to resources for basic datasets, the SUBTOTAL function grants you the power to dynamically ignore collapsed or filtered rows seamlessly. However, as a crucial stipulation, you must use the 100-series function codes-such as 109 instead of 9-to successfully exclude manually hidden rows. For example, using =SUBTOTAL(109, A2:A100) ensures only visible data is aggregated. Below, we will break down how to apply these formulas to master your dynamic reporting.

How to Sum and Aggregate Only Visible Cells in Filtered Excel Rows

When working with large datasets in Microsoft Excel, filtering data is one of the most common tasks. However, a frequent source of frustration for Excel users is performing mathematical calculations-such as summing, counting, or averaging-on only the visible data after a filter has been applied.

By default, standard Excel functions like SUM, AVERAGE, and COUNT calculate across the entire referenced range, completely ignoring whether a row is visible or hidden. If you try to sum a column of filtered data using =SUM(A2:A100), Excel will return the total of all 99 rows, including the ones hidden by your filter.

To aggregate only visible cells, you need specialized functions designed to respect Excel's filtering states. In this guide, we will explore the two most powerful functions for this task-SUBTOTAL and AGGREGATE-and dive into advanced techniques like applying conditional logic (e.g., SUMIFS) to visible rows only.

Method 1: The Classic Approach with the SUBTOTAL Function

For many years, the SUBTOTAL function has been the go-to solution for running calculations on filtered lists. It is highly versatile because it can perform 11 different operations (like sum, average, count, max, and min) depending on the "function number" you pass to it.

The Syntax of SUBTOTAL

=SUBTOTAL(function_num, ref1, [ref2], ...)

The magic of the SUBTOTAL function lies in its first argument, function_num. This number dictates both the math operation and how the function handles hidden rows. There are two sets of function numbers:

  • 1 to 11: These codes calculate visible rows and include rows that you have manually hidden (by right-clicking a row and choosing "Hide"). However, they exclude rows hidden by an active filter.
  • 101 to 111: These codes calculate visible rows and exclude all hidden rows-whether they were hidden by an active Excel filter or manually hidden by the user.

SUBTOTAL Function Codes Reference

Operation Includes Manually Hidden Rows (1-11) Excludes Manually Hidden Rows (101-111)
AVERAGE 1 101
COUNT (numbers only) 2 102
COUNTA (text and numbers) 3 103
MAX 4 104
MIN 5 105
SUM 9 109

Example: Summing Filtered Sales Data

Imagine you have a sales dataset in range C2:C100. To sum only the visible sales values after filtering by "Region" or "Product Class", use the following formula:

=SUBTOTAL(109, C2:C100)

If you filter the list to show only the "Midwest" region, this formula dynamically recalculates to display the sum of only those visible "Midwest" sales cells.


Method 2: The Modern and Robust AGGREGATE Function

Introduced in Excel 2010, the AGGREGATE function is a vastly superior alternative to SUBTOTAL. Not only can it calculate visible cells, but it also has the unique ability to completely ignore error values (such as #N/A, #DIV/0!, or #VALUE!) within your dataset.

If your dataset contains a single error, a standard SUBTOTAL or SUM formula will break and return that same error. AGGREGATE solves this elegantly.

The Syntax of AGGREGATE

=AGGREGATE(function_num, options, ref1, [ref2], ...)
  • function_num: Similar to SUBTOTAL, this specifies the operation. For example, 9 represents SUM, 1 is AVERAGE, and 3 is COUNTA. (Note: AGGREGATE supports up to 19 functions, including MEDIAN, MODE, and percentile calculations).
  • options: This is a code that tells Excel what data to ignore during calculation.

Crucial Option Codes for AGGREGATE

  • 3: Ignore hidden rows, error values, and nested SUBTOTAL/AGGREGATE functions.
  • 5: Ignore hidden rows only.
  • 6: Ignore error values only.
  • 7: Ignore hidden rows and error values.

Example: Summing Visible Rows While Ignoring Errors

If you want to sum visible cells in C2:C100 while bypassing any potential cell errors in that column, use function number 9 (SUM) with option code 7 (ignore hidden rows and errors):

=AGGREGATE(9, 7, C2:C100)

This is the most bulletproof way to perform basic calculations on dynamic, real-world spreadsheet data.


Advanced Scenario: "SUMIFS" on Visible Cells Only

A common roadblock is trying to perform a conditional sum (like SUMIFS) or a conditional count (like COUNTIFS) on filtered data. Since SUMIFS is programmed to scan the entire raw range regardless of visibility, standard formulas will fail to respect your active filters.

To overcome this, we can construct a specialized array formula combining SUMPRODUCT, SUBTOTAL, OFFSET, and ROW.

The Formula

Suppose we have a dataset where column B contains "Category" and column C contains "Revenue". We have applied a filter to another column (e.g., "Country"), and now we want to sum the visible revenue in C2:C100, but only where the Category in column B equals "Software".

=SUMPRODUCT((B2:B100="Software") * SUBTOTAL(109, OFFSET(C2, ROW(C2:C100)-MIN(ROW(C2:C100)), 0, 1)))

How It Works Under the Hood

  1. (B2:B100="Software"): This evaluates every cell in column B. It returns an array of TRUE and FALSE values (e.g., {TRUE; FALSE; TRUE; ...}).
  2. OFFSET(C2, ROW(C2:C100)-MIN(ROW(C2:C100)), 0, 1): This is the clever trick. It breaks down the range C2:C100 into an array of individual single-cell references. Excel normally processes ranges as a single block; this construction forces Excel to look at each row individually.
  3. SUBTOTAL(109, ...): Because SUBTOTAL is fed an array of individual cell references from the OFFSET step, it evaluates the visibility of each row one by one. It returns a 1 if the row is visible, and a 0 if it is hidden.
  4. SUMPRODUCT(...): Finally, SUMPRODUCT multiplies these arrays together:
    (Category is "Software") × (Row is Visible [1 or 0]) × (Revenue Value).
    If a row is hidden, it is multiplied by 0, excluding it from the final sum. If the category does not match, it is multiplied by 0 (FALSE), also excluding it. Only visible rows matching "Software" are summed.

  5. The "Helper Column" Alternative: Clean and Simple

    If the complex SUMPRODUCT/OFFSET formula feels too intimidating or slows down your workbook, you can use the highly efficient "Helper Column" method. This is often preferred in professional environments because it is easier to audit and troubleshoot.

    Step-by-Step Implementation:

    1. In your raw data table, add a new column and name it "Is Visible". Assuming your data starts at row 2, enter this formula in cell D2:
      =SUBTOTAL(103, C2)
      (Note: We use 103 (COUNTA) pointing to a cell in the same row that is never empty. If the row is visible, the formula returns 1. If the row is hidden, it returns 0.)
    2. Drag this formula down to the bottom of your table.
    3. Now, you can use standard, fast-performing Excel functions like SUMIFS or COUNTIFS by referencing your helper column. For example, to sum visible "Software" revenue:
      =SUMIFS(C2:C100, B2:B100, "Software", D2:D100, 1)

    This approach bypasses volatile functions like OFFSET, resulting in faster calculation speeds on large datasets with thousands of rows.


    Summary: Which Method Should You Use?

    • Use SUBTOTAL (109) if you need a quick, simple sum of filtered cells and your data contains no errors.
    • Use AGGREGATE (9, 7) as your default standard for summing filtered data, as it cleanly handles hidden rows and ignores potential error cells in your range.
    • Use the SUMPRODUCT + SUBTOTAL + OFFSET array formula if you must do complex conditional logic (like SUMIFS) on filtered data without changing your spreadsheet structure.
    • Use the Helper Column ("Is Visible") method for large spreadsheets where calculation speed and simple formulas are critical.

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.