How to Sum Filtered Rows in Excel

📅 Jul 26, 2026 📝 Sarah Miller

Consolidating horizontal data in Excel becomes frustrating when active filters skew your totals by including hidden rows. While standard SUM functions or vertical SUBTOTAL methods work well for traditional columns, dynamic row-level summation requires a more sophisticated approach. Mastering this technique ensures flawless, real-time reporting that adapts instantly to visible data. However, as a crucial stipulation, remember that Excel filters vertically; summing filtered rows horizontally requires nesting functions. For example, combining SUMPRODUCT with SUBTOTAL and OFFSET allows you to isolate visible cells in row 2. Below, we outline the step-by-step formula to implement this solution seamlessly.

How to Sum Filtered Rows in Excel

Excel Formula to Sum Row with Filter: A Comprehensive Guide

Excel is an indispensable tool for data analysis, but working with filtered datasets can often lead to unexpected results. If you have ever applied a filter to a table and noticed that your standard SUM formula still adds up the hidden rows, you are not alone. By default, the SUM function calculates every cell in the specified range, regardless of whether it is visible, filtered out, or manually hidden.

To accurately sum rows while ignoring filtered-out data, you need to use specialized functions. In this guide, we will explore several powerful Excel formulas-including SUBTOTAL, AGGREGATE, and the modern SUM combined with FILTER-to help you sum visible data horizontally (rows) and vertically (columns) with ease.

Why the Standard SUM Function Fails on Filtered Rows

Before diving into the solutions, it is important to understand the behavior of the standard SUM formula:

=SUM(A2:A10)

If you filter this dataset to show only three rows, the formula above will still return the total for all nine rows. Excel designed SUM to look at the underlying cell values, ignoring the sheet's visual state. To bypass this limitation, we must use functions that are "filter-aware."


Method 1: Summing Visible Rows Using the SUBTOTAL Function

The most common and classic approach to summing filtered data in Excel is the SUBTOTAL function. This function is specifically designed to perform calculations on a range while automatically ignoring rows hidden by a filter.

The Formula Syntax

=SUBTOTAL(function_num, ref1, [ref2], ...)
  • function_num: A number that specifies which function to use for the subtotal (e.g., Sum, Average, Count). For summing, you will use either 9 or 109.
  • ref1: The range of cells you want to sum.

Difference Between 9 and 109

Choosing the right function number is crucial depending on how your data is hidden:

Function Number Behavior with Filters Behavior with Manually Hidden Rows
9 Ignores rows hidden by an AutoFilter. Includes manually hidden rows.
109 Ignores rows hidden by an AutoFilter. Ignores manually hidden rows.

Example: To sum the visible cells in range C2:C100 while ignoring any rows that are manually hidden or filtered out, use:

=SUBTOTAL(109, C2:C100)

Method 2: Using the AGGREGATE Function for Advanced Filtering

Introduced in Excel 2010, the AGGREGATE function is a more powerful alternative to SUBTOTAL. Not only can it ignore filtered and hidden rows, but it can also ignore error values (like #N/A or #DIV/0!) and other nested subtotal formulas.

The Formula Syntax

=AGGREGATE(function_num, options, ref1, [ref2], ...)
  • function_num: Set this to 9 for SUM.
  • options: A behavior code. Use 5 to ignore hidden rows, or 7 to ignore both hidden rows and error values.
  • ref1: The range of cells to sum.

Example: If you want to sum D2:D100, ignoring filtered-out rows and any existing errors in the range, use:

=AGGREGATE(9, 7, D2:D100)

This formula ensures your dashboard totals do not break even if some underlying data contains errors.


Method 3: Summing Dynamically with SUM and FILTER (Excel 365 & 2021)

If you are using modern Excel (Microsoft 365 or Excel 2021), you can leverage the dynamic array FILTER function. Instead of relying on Excel's visual filters (AutoFilter), you can write a formula that filters and sums data dynamically based on specific criteria within the cells.

The Formula Syntax

=SUM(FILTER(sum_range, criteria_range = criteria))

Example Scenario

Suppose you have a sales table where column B contains the "Region" and column C contains the "Revenue". To sum the revenue for only the "North" region without manually applying a filter to the sheet, use:

=SUM(FILTER(C2:C100, B2:B100 = "North"))

Using Multiple Criteria

You can expand this to include multiple logical filters. For example, to sum revenue for "North" region sales that exceed $5,000:

=SUM(FILTER(C2:C100, (B2:B100 = "North") * (C2:C100 > 5000)))

Note: In Excel formulas, the asterisk (*) acts as the AND operator for array conditions.


Method 4: How to Sum a Row (Horizontal) with Filtered/Hidden Columns

A common pain point in Excel is trying to sum a single row horizontally (e.g., A2:Z2) while ignoring columns that have been manually hidden or filtered out.

Unlike rows, Excel's AutoFilter does not work horizontally, and SUBTOTAL or AGGREGATE formulas do not natively ignore hidden columns when applied to a horizontal range. However, we can solve this using a classic Excel trick involving the CELL function and SUMPRODUCT.

The Horizontal Solution (All Excel Versions)

To sum visible columns in row 2 from column B to G, you can use the following formula:

=SUMPRODUCT(B2:G2, --(CELL("width", OFFSET(B2, 0, COLUMN(B2:G2)-COLUMN(B2))) > 0))

How this formula works:

  1. OFFSET(B2, 0, COLUMN(B2:G2)-COLUMN(B2)) generates a reference to each individual cell in the range B2:G2.
  2. CELL("width", ...) evaluates the column width of each referenced cell. If a column is hidden, its width is returned as 0.
  3. > 0 checks if the column is visible (width greater than zero), returning TRUE or FALSE.
  4. The double unary operator (--) converts TRUE/FALSE values into 1/0.
  5. SUMPRODUCT multiplies the values in row 2 by the 1s and 0s, effectively excluding hidden columns from the final sum.

Important Note: Because Excel does not automatically trigger a recalculation when you simply hide or unhide a column, you may need to press F9 to force recalculation and update the formula's result.


Best Practices for Working with Filtered Sums

  • Use Excel Tables: Convert your flat ranges into official Excel Tables (press Ctrl + T). When you add a "Total Row" to an Excel Table, Excel automatically implements the SUBTOTAL function, saving you the trouble of writing the formulas manually.
  • Keep Recalculations in Mind: Complex array formulas (like the horizontal column hidden check) can slow down large workbooks. Use them sparingly on datasets exceeding tens of thousands of rows.
  • Prefer AGGREGATE Over SUBTOTAL: If you are working in Excel 2010 or newer, default to using AGGREGATE. It provides robust protection against workbook errors breaking your totals.

Conclusion

Summing filtered rows in Excel does not have to be a trial-and-error process. By replacing the basic SUM function with SUBTOTAL or AGGREGATE, you ensure your calculations adapt dynamically to whatever filters are applied. For modern workflows, utilizing the FILTER function allows you to bypass manual filtering entirely, streamlining your reporting dashboards and data analysis.

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.