SUBTOTAL Function in Excel: Totals That Respect Filters

⏱ 1 min readUpdated 28 September 2026

MathLevel: IntermediateAvailable in: Excel 2007+

In this article
  1. Syntax
  2. Examples
  3. Example 1
  4. Example 2
  5. Example 3
  6. Related functions

SUBTOTAL calculates a sum, count, average and more while ignoring rows hidden by a filter. It also ignores other SUBTOTALs in the range, so totals never double-count.

Syntax

=SUBTOTAL(function_num, ref1, [ref2], ...)
Argument What it means
function_num 9 = SUM, 1 = AVERAGE, 2 = COUNT, 3 = COUNTA, 4 = MAX, 5 = MIN. Add 100 (109, 101…) to also ignore manually hidden rows.
ref1 The range to calculate.

Examples

Example 1

=SUBTOTAL(9, E2:E500)

Sum of only the visible (filtered) rows.

Example 2

=SUBTOTAL(3, A2:A500)

How many rows are visible after filtering.

Example 3

=SUBTOTAL(109, E2:E500)

Also skips rows you hid by right-click → Hide.

💡 Excel Tables use SUBTOTAL automatically in their Total Row.

AGGREGATE · SUM · SUMIFS

📚 Part of the free Excel course: Beginner → Expert · Try it in the Formula Lab or ask the AI Helper.

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free · AI can be wrong