SUBTOTAL: a total that respects filters

Lesson 7 of 54

SUBTOTAL calculates a total, average or count that ignores rows hidden by a filter, and skips other SUBTOTALs inside its range so totals are never counted twice.

In cell D2, write a formula that adds up the Amount column (B2:B7) using SUBTOTAL with function number 9 (SUM).

D2
ABCD
1ExpenseAmountTotal
2Rent2,500
3Payroll8,200
4Software640
5Travel1,150
6Supplies310
7Marketing1,900

Type in the formula bar above and press Enter to check.

Skip

How SUBTOTAL works

Syntax

=SUBTOTAL(function_number, range1, [range2], ...)
function_number
9 = SUM, 1 = AVERAGE, 2 = COUNT, 3 = COUNTA, 4 = MAX, 5 = MIN. Add 100 (109, 101...) to also ignore rows hidden by hand.
range1, range2...
The cells to calculate.

Example

Invoices are in a filtered table with amounts in D2:D500. You want the average of the rows currently visible.

=SUBTOTAL(101, D2:D500)

Filter by client and the average updates to that client's invoices only.

Common mistakes

  • Expecting 9 to ignore rows hidden manually (right-click, Hide). Only 109 does that.
  • Using SUM under a filtered table and wondering why the total doesn't change.

Questions people ask

What is the difference between SUBTOTAL and AGGREGATE?

AGGREGATE (Excel only) can also ignore error values. SUBTOTAL works in Excel and Google Sheets and is enough for filtered totals.

Practice it above: type the formula in the formula bar and press Enter to check.