← All comparisons

SUM vs SUBTOTAL: why your filtered totals are wrong

Filter a table and SUM keeps adding the rows you just hid — that's the bug that leads people here. SUBTOTAL(9,...) counts only what's visible after filtering, and it has a second superpower: SUBTOTALs ignore other SUBTOTALs, so section totals plus a grand total never double-count.

The differences at a glance

SUMSUBTOTAL
Rows hidden by a FILTERStill includedExcluded (any function code)
Rows hidden manuallyStill includedCode 9: included · Code 109: excluded
Ignores other subtotals in its rangeNo — double-counts themYes — nested totals just work
Other aggregatesSUM only11 functions by code: 1=AVERAGE, 2=COUNT, 3=COUNTA, 4=MAX, 5=MIN, 9=SUM...
CompatibilityUniversalUniversal (every version of all three apps we test)

Which should you use?

Compatibility (from executed tests)

Both execute correctly in every version of all three apps we test, including the 100-series codes. AGGREGATE (Excel/LibreOffice, not Google Sheets) extends the idea with error-ignoring — that one IS a portability decision.

Example formulas

Filter-aware total=SUBTOTAL(9,C2:C100)
Also ignore manually hidden rows=SUBTOTAL(109,C2:C100)
Visible-row count=SUBTOTAL(3,A2:A100)

Full per-version details on each function page: SUM · SUBTOTAL.