How to sum only the filtered (visible) rows
✓ Verified in LibreOffice 25.8.7.3 ✓ Verified in Google Sheets (2026-08-30)Total that updates to match a filter — sum just the rows currently showing, ignoring anything the AutoFilter has hidden.
The formula
| App | Formula | Notes |
|---|---|---|
| Excel (desktop) | =SUBTOTAL(9,B2:B100) | 9 = SUM over visible-after-filter rows. Use 109 to also skip rows you hid manually. A plain =SUM would keep counting hidden rows. |
| Google Sheets | =SUBTOTAL(9,B2:B100) | Identical. Sheets' function code 9 also ignores rows hidden by a filter. |
| LibreOffice Calc | =SUBTOTAL(9,B2:B100) | Identical. |
How it works
SUBTOTAL's first argument picks the operation and, crucially, whether hidden rows count. Code 9 means SUM but ignores rows hidden by an AutoFilter, so the total tracks whatever the filter leaves visible — here all four rows are visible, giving 100, but hide any and the result drops automatically. Use 109 instead of 9 to also exclude rows you hid by hand (not via a filter); codes 1/101 do AVERAGE, 2/102 COUNT, 3/103 COUNTA, 4/104 MAX, and so on. A bonus: SUBTOTAL ignores other SUBTOTAL cells in its range, so grand totals don't double-count subtotals. For summing visible cells with a condition on top, AGGREGATE(9,5,range) or a SUMPRODUCT with SUBTOTAL gives finer control.
Verified, not just documented
We ran =SUBTOTAL(9,B2:B5) in LibreOffice 25.8.7.3 (headless, with forced recalculation) and it returned 100 — exactly the expected result. We then ran the same formulas in Google Sheets, executed 2026-08-30: a formula-only workbook goes into Google Drive, which converts it to a Sheet and recalculates every formula with Google’s own engine, and comes back out as .xlsx carrying the values Google computed. It returned 100 for the worked example, the same value LibreOffice produced. Both engines’ numbers on this page are executed results. The Excel formula follows Microsoft’s official documented syntax — we do not run desktop Excel.
Functions used
SUBTOTAL — see full Excel, Google Sheets & LibreOffice compatibility for each.
Related recipes
- How to count cells by color (and why formulas can't see color)
- How to count only visible rows after filtering