← 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 (documented across all versions; executed in every LibreOffice version we test)

Which should you use?

Compatibility (Excel for the web, Sheets & LibreOffice executed; desktop Excel per docs)

Both execute correctly in every LibreOffice version we test (desktop Excel behavior per docs — we do not run desktop Excel; Google Sheets is executed separately, see each function page), including the 100-series codes. AGGREGATE (Excel/LibreOffice, not Google Sheets) extends the idea with error-ignoring — that one IS a portability decision. Excel for the web is a separate application with its own calculation engine, and that one we do execute: all 7 corpus cases for these functions matched the documented values there (recalculated on OneDrive, 2026-09-01); the per-case values are on the individual function pages.

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.

How-to recipes using these functions