Learn Excel
EN

Home › Excel functions › SUBTOTAL

SUBTOTAL Function in Excel: Sum Filtered and Visible Cells

SUBTOTAL calculates a sum, count, average or other statistic for a range, but ignores rows that are hidden by a filter. Filter your list on one region and the total updates to show just that region.

In this guide
  1. SUBTOTAL syntax
  2. Function numbers
  3. Sum filtered data
  4. Count visible rows
  5. No double counting
  6. Common mistakes
  7. FAQ

SUBTOTAL syntax

=SUBTOTAL(function_num, ref1, [ref2], …)
ArgumentWhat it means
function_numA number that tells SUBTOTAL which calculation to do, such as 9 for SUM or 109 for SUM ignoring hidden rows. See the table below.
ref1, ref2, …The range or ranges to calculate on.

Function numbers

CalculationIncludes manually hidden rowsIgnores manually hidden rows
AVERAGE1101
COUNT (numbers)2102
COUNTA (non-empty)3103
MAX4104
MIN5105
PRODUCT6106
STDEV7107
STDEVP8108
SUM9109
VAR10110
VARP11111

1–11 vs. 101–111: both versions ignore rows hidden by a filter. The difference is rows you hide yourself (right-click › Hide): 1–11 still include them, 101–111 leave them out. If you're unsure, use 101–111: they always calculate only what you can see.

Example: sum a filtered list

ABC
1RegionRepSales
2NorthAnna1,200
3SouthBen800
4NorthChris950
5EastDana450
6SouthAnna700
7Total4,100
=SUBTOTAL(109, C2:C6)

With no filter, C7 shows 4,100, the same as SUM. Now filter column A on "North" (Data › Filter). Rows 3, 5 and 6 are hidden and the total changes to 2,150: only the visible rows are added. A normal =SUM(C2:C6) would keep showing 4,100.

Count or average visible rows

  • Count the visible rows: =SUBTOTAL(103, A2:A6) counts the non-empty visible cells. After filtering on North, it returns 2.
  • Average of what's visible: =SUBTOTAL(101, C2:C6) returns 1,075 for North.
  • Highest visible value: =SUBTOTAL(104, C2:C6) returns 1,200 for North.

Tip: put the SUBTOTAL formulas above the list instead of below it. Then they stay visible when the list gets long.

SUBTOTAL ignores other subtotals

If a range contains cells that themselves use SUBTOTAL, those cells are skipped. That means you can add subtotals per group and a grand total over the whole column, without counting anything twice. This is exactly what Excel's built-in Data › Subtotal command does: it inserts SUBTOTAL formulas for each group and one for the grand total. The total row of an Excel table (Ctrl+T, then Table Design › Total Row) uses SUBTOTAL too.

Common mistakes

  • The total doesn't change when you hide rows manually. You used 1–11. Switch to 101–111.
  • Hidden columns are still included. SUBTOTAL only ignores hidden rows. It doesn't skip hidden columns in a horizontal range.
  • #VALUE! The function number isn't one of 1–11 or 101–111.
  • You need to ignore errors as well. Use AGGREGATE, which works like SUBTOTAL but can also skip error values: =AGGREGATE(9, 7, C2:C6).

Frequently asked questions

What is the difference between SUBTOTAL 9 and 109?

Both add up only the rows that are visible after filtering. 109 also skips rows you've hidden manually; 9 still includes them.

How do I sum only visible cells in Excel?

Use =SUBTOTAL(109, range). It ignores rows hidden by a filter and rows hidden manually.

Why use SUBTOTAL instead of SUM?

SUM always adds every cell in the range. SUBTOTAL respects filters and skips other subtotals, so it gives the right total for whatever is currently visible.

What is AGGREGATE?

AGGREGATE is a more powerful version of SUBTOTAL, available since Excel 2010. It offers more calculations and can also ignore error values.