SUBTOTAL Function in Excel: Totals That Respect Filters

SUBTOTAL Function in Excel: Totals That Respect Filters featured illustration

📎 This article includes 1 downloadable practice file ↓

⏱ 2 min readUpdated 5 October 2026

MathLevel: IntermediateAvailable in: Excel 2007+

In this article
  1. Syntax
  2. Examples
  3. Example 1
  4. Example 2
  5. Example 3
  6. SUBTOTAL in practice
  7. Where you will use it
  8. Worked example
  9. Mistakes people make
  10. Related functions
  11. Continue learning

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.

Advertisement

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.

SUBTOTAL in practice

Where you will use it

  • Totals that ignore hidden or filtered rows
  • Sum visible rows only after filtering
  • Counts in grouped reports

Worked example

9 = SUM, 1 = AVERAGE, 3 = COUNTA.

Function no.AprMayJunFormulaResult
9100200300=SUBTOTAL(A2,B2:D2)600
1100200300=SUBTOTAL(A3,B3:D3)200
3100200300=SUBTOTAL(A4,B4:D4)3

Results calculated in Excel.

Mistakes people make

MistakeWhat to do instead
Using 9 when rows are hidden manuallyUse 109 to ignore manually hidden rows too
Nested subtotalsSUBTOTAL ignores other SUBTOTALs, avoiding double counting

AGGREGATE · SUM · SUMIFS

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

⚡ Interactive Practice Lab & Formula Tester:

Test formulas dynamically in our web formula laboratory or download the companion Excel workbook.

📎 Practice files for this article

  • 📗
    Practice workbook: Math & rounding24 tasks on realistic sales data — type your formula, the Check column turns green when it is right. Answers sheet included.
    ⬇ XLSX · 35 KB

Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.

✨ Ask AI about this article

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

Free · AI can be wrong