SUBTOTAL vs SUM in Excel: Totals That Respect Filters
By ExcelReady TeamUpdated 7 min read
The short answer
SUM adds every number in a range, whether rows are filtered, hidden or already totals. SUBTOTAL with 9 adds only the rows a filter leaves visible and skips other SUBTOTAL formulas, so group totals aren't counted twice. SUBTOTAL with 109 also skips rows you hid by hand. Use SUM for fixed totals and SUBTOTAL for lists people filter.
Key takeaways
- =SUBTOTAL(9,C2:C20) adds only visible rows after a filter; =SUM(C2:C20) adds all rows.
- SUBTOTAL ignores other SUBTOTAL formulas in its range, so a grand total never double counts group totals.
- Function number 9 ignores filtered rows; 109 also ignores rows hidden by hand.
- SUBTOTAL can also count, average or find the max of visible rows, using other function numbers.
On this page+
The short answer to SUBTOTAL vs SUM: SUM adds every number in a range, while SUBTOTAL adds only the rows that are visible after a filter and skips other subtotals inside the range. On a plain list they give the same answer. The difference appears as soon as someone filters the data or adds group totals. This comparison is for anyone who builds reports that other people filter, or who has seen a grand total come out exactly double.
SUBTOTAL vs SUM at a glance#
SUM is simple and counts everything; SUBTOTAL is aware of filters, hidden rows and other subtotals.
| Feature | SUM | SUBTOTAL |
|---|---|---|
| Syntax | =SUM(number1, [number2], ...) | =SUBTOTAL(function_num, ref1, [ref2], ...) |
| Rows hidden by a filter | Included | Excluded |
| Rows hidden by hand | Included | Included with 9, excluded with 109 |
| Other SUBTOTAL formulas in the range | Included (double counting) | Excluded |
| Hidden columns | Included | Included |
| Other calculations | Adding only | Sum, count, average, max, min and more |
Accepts single numbers like =SUM(5,10) | Yes | No, ranges only |
| Excel versions | All versions | All versions |
How SUM works#
SUM adds every number you give it: ranges, single cells or typed numbers.
=SUM(C2:C7)
=SUM(C2:C7,E2:E7)
=SUM(C2,C5,100)It ignores text and empty cells but includes everything else, even rows you can't see. That makes it predictable and fast, and it is the right choice for most fixed totals. The SUM function guide covers every form, and the article on the SUM function has more everyday examples, including totals that span several sheets.
How SUBTOTAL works#
SUBTOTAL takes a function number that says which calculation to do, then one or more ranges.
=SUBTOTAL(9,C2:C7)
=SUBTOTAL(109,C2:C7)The most common function numbers are:
| Calculation | Skips filtered rows | Also skips rows hidden by hand |
|---|---|---|
| AVERAGE | 1 | 101 |
| COUNT (numbers) | 2 | 102 |
| COUNTA (non-empty) | 3 | 103 |
| MAX | 4 | 104 |
| MIN | 5 | 105 |
| SUM | 9 | 109 |
Every SUBTOTAL, whatever the number, skips rows hidden by a filter and ignores other SUBTOTAL formulas in its range. The SUBTOTAL function guide and the article on the SUBTOTAL function list all eleven calculations.
When SUM and SUBTOTAL both fail: errors#
Both functions stop at an error. If one cell in the range shows #N/A or #DIV/0!, =SUM(C2:C7) and =SUBTOTAL(9,C2:C7) both return that error. In Excel 2010 and later, AGGREGATE fixes this. It works like SUBTOTAL with an extra options argument:
=AGGREGATE(9,6,C2:C7)Here 9 means sum and 6 means "ignore error values", so the formula adds every number and skips the broken cells. Option 7 ignores both hidden rows and errors. AGGREGATE is worth knowing for messy imported data, but SUBTOTAL remains the more common choice in reports because it is shorter and older files use it everywhere.
The same data with SUM and SUBTOTAL#
Here is a sales list with six rows, totalling 700:
| A | B | C | |
|---|---|---|---|
| 1 | Region | Rep | Sales |
| 2 | North | Kofi | 100 |
| 3 | North | Mei | 150 |
| 4 | South | Ravi | 200 |
| 5 | South | Lena | 50 |
| 6 | East | Ana | 120 |
| 7 | North | Tom | 80 |
Test 1: no filter#
=SUM(C2:C7) and =SUBTOTAL(9,C2:C7) both return 700. With nothing hidden, they are identical.
Test 2: filter to North#
Turn on a filter (Data > Filter, or Ctrl+Shift+L on Windows and ⌘⇧F on a Mac) and show only North. Rows 4, 5 and 6 disappear.
=SUM(C2:C7)still returns 700.=SUBTOTAL(9,C2:C7)returns 330, the total of the three North rows on screen.
Anyone reading the filtered report would expect 330. The SUM total no longer matches what they see. The filter lesson shows how filters hide rows, and how to filter and sum builds a full filtered report.
Test 3: hide a row by hand#
Clear the filter, then right-click row 4 and choose Hide.
=SUBTOTAL(9,C2:C7)returns 700: 9 ignores filters, not manual hiding.=SUBTOTAL(109,C2:C7)returns 500: 109 also skips the hidden row.
Test 4: group totals inside the range#
Now picture a report with a subtotal under each region, as in the exercise on this page: North rows of 100 and 150 with =SUBTOTAL(9,C2:C3) below them, and South rows of 200 and 50 with =SUBTOTAL(9,C5:C6) below them. A grand total of =SUM(C2:C7) returns 1,000, because it adds the four sales and both group totals. =SUBTOTAL(9,C2:C7) returns 500, the correct grand total, because it skips the other SUBTOTAL cells.
This is how Excel's own Data > Subtotal command works: it inserts SUBTOTAL formulas so the grand total stays correct.
When to use SUM#
Use SUM when the total should always include every row. It fits:
- Fixed totals that must not change when someone filters, such as a budget total or an invoice total.
- Adding single cells or typed numbers, such as
=SUM(B2,D2,F2). - Totals across sheets, such as
=SUM(Jan:Dec!C10). See summing across sheets. - Simple lists that no one will filter or group, where SUM is the shortest and clearest choice.
The SUM lesson practises these basics.
When to use SUBTOTAL#
Use SUBTOTAL when the total should follow what is on screen. It fits:
- Lists people filter, such as a sales log where managers pick a region.
- Reports with group totals and a grand total in the same column.
- Counting visible rows, such as
=SUBTOTAL(3,A2:A100)to show how many records match the filter. - Excel tables. The Total Row of a table uses SUBTOTAL with 109, so totals update with the filter automatically.
- Hiding rows by hand for a quick what-if: use 109 so the total ignores them.
When you use AutoSum (Alt+= on Windows, ⌘⇧T on a Mac) directly below a filtered list, Excel inserts SUBTOTAL(9, ...) instead of SUM for you. The guide to summing visible cells only covers more methods.
Common mistakes with SUBTOTAL and SUM#
- Using SUM on a filtered report. The total shows all rows, not what the reader sees. Use SUBTOTAL.
- Double counting group totals. A SUM grand total over a column with subtotals adds them twice. Use SUBTOTAL for both the group totals and the grand total.
- Using 9 when you hide rows by hand. 9 only skips filtered rows. Use 109 to skip manually hidden rows too.
- Expecting SUBTOTAL to skip hidden columns. It works down columns only. Hidden columns in a horizontal total are still added.
- Mixing SUM and SUBTOTAL for group totals. If group totals use SUM, a SUBTOTAL grand total will include them, because it only skips other SUBTOTAL cells.
- Forgetting the function number.
=SUBTOTAL(C2:C7)is not valid. The function number always comes first.
Our recommendation#
Use SUM for totals that should always include every row, and for adding individual cells. Use SUBTOTAL, usually with 109, for any list that people will filter or hide rows in, and for any column that mixes group totals with a grand total. If you aren't sure whether a report will be filtered, SUBTOTAL is the safer choice: it gives the same answer as SUM until a filter appears, then keeps matching the screen.
In short: SUM for fixed totals, SUBTOTAL for anything that gets filtered or grouped.
Practise it#
Try the exercise on this page: build a grand total that skips the group subtotals. Then practise filters in a live spreadsheet and review the SUM function lesson: you type each formula, and it checks your answer instantly.
Try it yourself
This is a live spreadsheet. Type the formula in the green cell and press Enter.
Rows 4 and 7 already hold group subtotals. In C8, use SUBTOTAL with function number 9 to calculate the grand total of C2:C7 without counting the group totals twice.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Sales | |||
| 2 | ||||
| 3 | ||||
| 4 | North total | |||
| 5 | ||||
| 6 | ||||
| 7 | South total | |||
| 8 | Grand total | |||
| 9 | ||||
| 10 | ||||
| 11 |
Tip: SUBTOTAL needs the function number first (9 means sum), then the whole range, C2:C7. It skips the two subtotal cells by itself.
Practise this in a lesson
Frequently asked questions
What is the difference between SUBTOTAL and SUM in Excel?
SUM adds every number in the range. SUBTOTAL(9, range) adds only the rows that are visible after filtering and skips other SUBTOTAL formulas. On an unfiltered list with no group totals, they return the same result.
What is the difference between SUBTOTAL 9 and 109?
Both add visible rows after a filter. 9 still includes rows you hid by hand with Hide, while 109 leaves them out too.
Why does my SUM include filtered rows?
SUM always adds every cell in its range. To total only what the filter shows, use =SUBTOTAL(9, range) or =SUBTOTAL(109, range).
Does SUBTOTAL ignore hidden columns?
No. SUBTOTAL only skips hidden rows. If you total across a row and hide a column, the hidden value is still included.
How do I sum only visible cells in Excel?
Use =SUBTOTAL(109, range). It skips rows hidden by a filter and rows hidden by hand. AutoSum also inserts SUBTOTAL automatically when you use it below a filtered list.