Total only the rows you can see with SUBTOTAL
Work with long lists8 minPremium
Builds on Filter a list to the rows you need and Add it up with SUM.
A finance assistant in Dublin filters the travel claims by department before each budget meeting. Whatever she filters, the SUM under the list keeps showing the whole company's claims.
How it works
SUBTOTAL( runs a function over a range and leaves out the rows a filter hides. Its first argument picks the function, and whether rows you hid yourself with Hide still count:
| Row | A | B | C |
|---|---|---|---|
| 1 | Function | Rows hidden with Hide count | Rows hidden with Hide are left out |
| 2 | AVERAGE | 1 | 101 |
| 3 | COUNT (numbers) | 2 | 102 |
| 4 | COUNTA (filled cells) | 3 | 103 |
| 5 | MAX | 4 | 104 |
| 6 | MIN | 5 | 105 |
| 7 | SUM | 9 | 109 |
Rows a filter hides are left out with either number. SUBTOTAL also skips any SUBTOTAL formulas inside its range, so a grand total over a column that already holds group totals counts each amount once. On a filtered list, AutoSum writes a SUBTOTAL for you instead of a SUM.
AGGREGATE uses the same numbers for its first eleven functions, 9 for SUM included, and adds a second argument that says what to skip: 5 skips hidden rows, 6 skips error values such as #N/, and 7 skips both.
Example
The claims list has departments in B2:B7 and amounts in C2:C7, and it's filtered to Marketing.
=SUBTOTAL(9,C2:C7)| Department | Amount | SUM | SUBTOTAL |
|---|---|---|---|
| Marketing | €310 | adds | adds |
| Finance | €146 | adds | skips |
| Marketing | €88 | adds | adds |
| IT | €412 | adds | skips |
| Marketing | €65 | adds | adds |
| Finance | €230 | adds | skips |
=SUM( C2:C7) still adds all six claims and shows €1,251, while =SUBTOTAL( 9, C2:C7) skips the hidden ones and shows €463.Common mistakes
=SUM(under a filtered list adds the hidden rows as well. Total with SUBTOTAL and 9 or 109.C2:C7) - 9 still counts rows hidden with Hide. When someone has hidden rows by hand, use 109.
=SUBTOTAL(counts numbers only, so on a column of names or codes it shows 0. Count filled cells with 3 or 103.2, A2:A7) - A SUM over a column that holds subtotals counts every amount twice. Total it with SUBTOTAL, which skips them.
In short
SUBTOTAL(totals the rows a filter shows, and 109 also leaves out rows hidden with Hide.9, range) - 1 averages, 2 counts numbers, 3 counts filled cells; add 100 to skip rows hidden by hand.
- SUBTOTAL skips other SUBTOTALs, so a grand total doesn't count anything twice.
AGGREGATE(also skips error values.9, 7, range)
Practice
Premium4 formulas.
Practice is part of Premium
Every lesson is free to read, and you can practice the free lessons without an account. This lesson's exercises are part of Premium, which you add to a free account.
Have one? Sign in