SUBTOTAL Function

Excel Functions › Math & Trig

All versions Math & Trig

The Excel SUBTOTAL function aggregates a range with one of 11 operations (SUM, AVERAGE, COUNT, MAX, …) while ignoring rows hidden by a filter — and, optionally, rows you hide by hand.


Quick answer:
=SUBTOTAL(9,B2:B10) SUMs B2:B10, skipping filtered-out rows

Syntax

=SUBTOTAL(function_num, ref1, [ref2], ...)
ArgumentDescription
function_numRequiredA number choosing the operation: 1-11 (e.g. 9 = SUM, 1 = AVERAGE, 2 = COUNT, 4 = MAX) ignore filtered rows; 101-111 also ignore manually hidden rows.
ref1RequiredThe first range to aggregate.
ref2, ...OptionalUp to 253 more ranges.

How to use it

SUBTOTAL's first argument picks the math. Codes 1–11 ignore rows hidden by a filter; codes 101–111 also ignore rows you hide manually.

=SUBTOTAL(9, B2:B10) // SUM, ignores filtered rows
=SUBTOTAL(109, B2:B10) // SUM, also ignores manually hidden rows
=SUBTOTAL(1, B2:B10) // AVERAGE of visible rows

The clever part: SUBTOTAL ignores other SUBTOTAL cells in its range, so a grand total made of SUBTOTAL won't double-count nested subtotals. That's why Excel's Data > Subtotal feature uses it.

Common codes: 1 AVERAGE, 2 COUNT, 3 COUNTA, 4 MAX, 5 MIN, 6 PRODUCT, 9 SUM. Add 100 (101, 109, …) to also drop manually hidden rows.

Try it: interactive demo

Live demo

Pick a SUBTOTAL example to see the formula and its result.

Result:

Practice workbook

📊
Download the free SUBTOTAL practice workbook
Every example on this page, ready to open in Excel — plus practice challenges with answers on a separate tab. No sign-up required.

Frequently asked questions

What does the function_num argument mean?
It selects the operation: 9 = SUM, 1 = AVERAGE, 2 = COUNT, 4 = MAX, 5 = MIN, and so on. Codes 1–11 ignore filtered rows; 101–111 also ignore manually hidden rows.
What is the difference between 9 and 109?
Both SUM. Code 9 ignores rows hidden by a filter but still counts rows you hide by hand; code 109 ignores both filtered and manually hidden rows.
Why doesn't SUBTOTAL double-count other subtotals?
By design it skips any cell in its range that is itself a SUBTOTAL, so a grand-total SUBTOTAL over a column that already has sub-group SUBTOTALs stays correct.
Does SUBTOTAL work on filtered data?
Yes — that's its main purpose. With an AutoFilter applied, =SUBTOTAL(9,...) totals only the visible (matching) rows and updates as you change the filter.

Master functions like this in one day

This page covers one function. Our Excel Formulas and Functions class covers the 30 that matter most — live, hands-on, taught by professionals in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.

See the Formulas & Functions Class

Related functions: AGGREGATE · SUM · SUMIF · COUNT · AVERAGE