SUBTOTAL vs AGGREGATE in Excel: Totals That Skip Rows
By ExcelReady TeamUpdated 8 min read
The short answer
SUBTOTAL and AGGREGATE both total or count only the rows a filter shows. SUBTOTAL is simpler and works in every version, but one error in the range breaks it. AGGREGATE, from Excel 2010, adds an options argument that can skip errors and hidden rows, plus extra functions such as MEDIAN, LARGE and SMALL.
Key takeaways
- SUBTOTAL(9,range) sums visible rows. AGGREGATE(9,7,range) sums visible rows and skips errors too.
- SUBTOTAL returns an error if any visible cell has one. AGGREGATE with option 6 or 7 ignores it.
- AGGREGATE has 19 functions, including MEDIAN, LARGE and SMALL. SUBTOTAL has 11.
- Filtered rows: SUBTOTAL always skips them. AGGREGATE skips them only with options 1, 3, 5 or 7.
- Use SUBTOTAL for clean, filtered lists and AGGREGATE when errors are possible or you need LARGE or SMALL.
On this page+
SUBTOTAL vs AGGREGATE comes down to errors and extra functions. Both give totals that skip the rows a filter hides. SUBTOTAL is shorter and works in every version, but a single #N/A or #DIV/0! in the range breaks it. AGGREGATE can ignore errors and offers more calculations, such as MEDIAN, LARGE and SMALL. This guide compares them on the same data, so you can pick the right one for a report or a job test.
SUBTOTAL vs AGGREGATE at a glance#
AGGREGATE is SUBTOTAL with more functions and more control over what to skip.
| Feature | SUBTOTAL | AGGREGATE |
|---|---|---|
| Syntax | =SUBTOTAL(function_num, ref1, ...) | =AGGREGATE(function_num, options, ref1, ...) |
| Number of functions | 11 | 19 |
| Extra functions | None | MEDIAN, MODE.SNGL, LARGE, SMALL, percentiles, quartiles |
| Rows hidden by a filter | Always skipped | Skipped with options 1, 3, 5 or 7 |
| Rows hidden by hand | Skipped with 101–111 | Skipped with options 1, 3, 5 or 7 |
| Error values in the range | Returns the error | Skipped with options 2, 3, 6 or 7 |
| Other SUBTOTALs in the range | Skipped | Skipped with options 0 to 3 |
| Hidden columns | Not skipped | Not skipped |
| Excel versions | All versions | Excel 2010 and later |
| Inserted by Excel for you | Yes: table Total Row, Data > Subtotal | No, you type it |
How SUBTOTAL works#
SUBTOTAL runs one of 11 calculations on the visible rows of a range. The first argument is a function number:
=SUBTOTAL(9,C2:C7)9 means SUM. Other common numbers are 1 (AVERAGE), 2 (COUNT), 3 (COUNTA), 4 (MAX) and 5 (MIN). Add 100 to skip rows you hid by hand as well as filtered rows: =SUBTOTAL(109,C2:C7). SUBTOTAL also ignores other SUBTOTAL formulas inside its range, so group subtotals aren't counted twice.
The SUBTOTAL function guide lists all 11 numbers. For how it compares with a plain SUM, see SUBTOTAL vs SUM.
How AGGREGATE works#
AGGREGATE has the same idea plus a second argument, options, which says what to skip:
=AGGREGATE(function_num, options, ref1, ...)| Option | What it skips |
|---|---|
| 0 or omitted | Nested SUBTOTAL and AGGREGATE formulas |
| 1 | Hidden rows, nested SUBTOTAL and AGGREGATE |
| 2 | Error values, nested SUBTOTAL and AGGREGATE |
| 3 | Hidden rows, errors, nested SUBTOTAL and AGGREGATE |
| 4 | Nothing |
| 5 | Hidden rows |
| 6 | Error values |
| 7 | Hidden rows and error values |
Functions 1 to 13 match SUBTOTAL's list and add 12 (MEDIAN) and 13 (MODE.SNGL). Functions 14 to 19 are LARGE, SMALL, PERCENTILE.INC, QUARTILE.INC, PERCENTILE.EXC and QUARTILE.EXC. They take an extra last argument, k: =AGGREGATE(14,6,C2:C7,2) returns the second-largest value.
Function numbers side by side#
Both functions share the first 11 numbers, so 9 means SUM in either one. Only AGGREGATE has 12 to 19.
| Number | Calculation | SUBTOTAL | AGGREGATE |
|---|---|---|---|
| 1 | AVERAGE | Yes (101 skips hidden) | Yes |
| 2 | COUNT | Yes (102) | Yes |
| 3 | COUNTA | Yes (103) | Yes |
| 4 / 5 | MAX / MIN | Yes (104 / 105) | Yes |
| 9 | SUM | Yes (109) | Yes |
| 12 / 13 | MEDIAN / MODE.SNGL | No | Yes |
| 14 / 15 | LARGE / SMALL | No | Yes, with k |
| 16 to 19 | Percentiles and quartiles | No | Yes, with k |
In AGGREGATE, the 100-series numbers don't exist. Hidden rows are controlled by the options argument instead.
The same data solved both ways#
Here is a small sales list. Chloe's cell shows #DIV/0! because the formula behind it divides by an empty cell.
| A | B | C | |
|---|---|---|---|
| 1 | Region | Rep | Sales |
| 2 | North | Ana | 400 |
| 3 | South | Ben | 250 |
| 4 | North | Chloe | #DIV/0! |
| 5 | East | Dev | 300 |
| 6 | South | Ema | 150 |
| 7 | North | Finn | 500 |
Task 1: total everything, despite the error#
=SUBTOTAL(9,C2:C7)
=AGGREGATE(9,6,C2:C7)SUBTOTAL returns #DIV/0!, just like =SUM(C2:C7). AGGREGATE returns 1,600 (400 + 250 + 300 + 150 + 500), because option 6 ignores errors.
Task 2: filter to South#
Filter the Region column to South (rows 3 and 6). Now the error row is hidden:
=SUBTOTAL(9,C2:C7)
=AGGREGATE(9,5,C2:C7)Both return 400 (250 + 150). SUBTOTAL works again because the cell with the error is no longer visible.
Task 3: filter to North#
Filter to North (rows 2, 4 and 7). Chloe's error is visible again:
=SUBTOTAL(9,C2:C7)
=AGGREGATE(9,7,C2:C7)SUBTOTAL returns #DIV/0!. AGGREGATE with option 7, which skips hidden rows and errors, returns 900 (400 + 500).
Task 4: the second-largest sale#
SUBTOTAL has no LARGE function, so it can't answer this. With the filter cleared:
=AGGREGATE(14,6,C2:C7,2)The result is 400: the largest is 500, then 400. Use option 7 instead of 6 to rank only the visible rows.
Task 5: rows hidden by hand#
Clear the filter, then hide row 5 (Dev) by right-clicking its row number and choosing Hide:
=SUBTOTAL(109,C2:C7)
=AGGREGATE(9,7,C2:C7)SUBTOTAL still returns #DIV/0!, because Chloe's row is visible. AGGREGATE returns 1,300: the 1,600 total minus Dev's 300. With =SUBTOTAL(9,C2:C7) and no error, Dev's 300 would still be counted, because 9 only skips rows hidden by a filter.
When to use SUBTOTAL#
Use SUBTOTAL when the data is clean and you only need totals, counts or averages of visible rows. It fits well when:
- You filter a list and want the total to match the screen. The guide to summing only visible cells covers this case.
- You use a table's Total Row or Data > Subtotal. Excel writes SUBTOTAL formulas for you there.
- The file must open in very old Excel, before 2010.
- Other people maintain the file. SUBTOTAL is more widely known, and
=SUBTOTAL(109,C2:C7)is easy to read.
When to use AGGREGATE#
Use AGGREGATE when errors might appear, or when you need a calculation SUBTOTAL doesn't have. It is the better choice when:
- The data has errors you can't fix yet, such as #N/A from a lookup on imported data. See how to sum and ignore errors for other approaches.
- You need MEDIAN, LARGE or SMALL on filtered rows, such as the top sale in the visible region.
- You need a conditional top value that skips errors. In the array form,
=AGGREGATE(14,6,C2:C7/(A2:A7="North"),1)returns the largest North sale, 500. Rows that aren't North become errors when divided by FALSE, and option 6 skips them along with Chloe's #DIV/0!. This form works only with functions 14 to 19.
Common mistakes with SUBTOTAL and AGGREGATE#
Most wrong results come from the function number or the option:
- Using AGGREGATE option 6 on a filtered list. Option 6 skips errors but still includes filtered rows. Use 7 to skip both.
- Mixing up the arguments. In AGGREGATE, the function number comes first and the option second.
=AGGREGATE(6,9,C2:C7)means PRODUCT with an invalid option, and Excel returns #VALUE!. - Using SUBTOTAL 9 after hiding rows by hand. 9 only skips filtered rows. Use 109.
- Expecting hidden columns to be skipped. Both functions skip hidden rows only. A horizontal range still includes hidden columns.
- Hiding errors you should fix. Skipping a #N/A means that row's value is missing from the total. Check why the error is there.
For the filter steps themselves, see how to filter data in Excel, and for SUBTOTAL's group-total uses, the SUBTOTAL function in Excel.
Our recommendation#
Use SUBTOTAL, usually with 109, for clean lists that people filter: it is short, familiar and built into tables. Switch to AGGREGATE when the range might contain errors, or when you need MEDIAN, LARGE or SMALL on visible rows. On a filtered list with possible errors, =AGGREGATE(9,7,range) is the safest total. And for fixed totals with no filters or errors, a plain SUM is still the simplest choice.
Practise it#
Totals that follow a filter are a common Excel test task. Practise filtering a table in a live spreadsheet: you'll filter by value and condition, then total and count only the visible rows with SUBTOTAL. If you need a refresher first, practise SUM and AutoSum. Every answer is checked the moment you press Enter. Or try the AGGREGATE exercise on this page.
Try it yourself
This is a live spreadsheet. Type the formula in the green cell and press Enter.
Chloe's sales cell shows #DIV/0!, so =SUM(C2:C7) fails. In F2, use AGGREGATE to sum C2:C7 while ignoring errors: function 9 for SUM, option 6 to ignore errors.
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Sales | ||||||
| 2 | Total sales | ||||||
| 3 | |||||||
| 4 | |||||||
| 5 | |||||||
| 6 | |||||||
| 7 | |||||||
| 8 | |||||||
| 9 | |||||||
| 10 |
Tip: AGGREGATE takes the function number first (9 is SUM), then the option (6 ignores errors), then the range.
Practise this in a lesson
Frequently asked questions
What is the difference between SUBTOTAL and AGGREGATE in Excel?
Both calculate on visible rows only. AGGREGATE adds an options argument that can also ignore error values, and it offers 19 functions instead of 11, including MEDIAN, LARGE and SMALL. SUBTOTAL works in every version of Excel, while AGGREGATE needs Excel 2010 or later.
What does AGGREGATE 9 6 mean?
In =AGGREGATE(9,6,C2:C7), 9 means SUM and 6 means ignore error values. It adds every number in the range and skips cells such as #N/A or #DIV/0!. It still includes hidden rows.
Does AGGREGATE ignore filtered rows?
Only with options 1, 3, 5 or 7. With options 0, 2, 4 or 6, AGGREGATE includes rows hidden by a filter. Use 5 to skip hidden rows, or 7 to skip hidden rows and errors.
Can SUBTOTAL ignore errors?
No. If any visible cell in the range contains an error, SUBTOTAL returns that error. Use AGGREGATE with option 6 or 7 instead, or fix the errors at the source.
Is AGGREGATE available in all versions of Excel?
AGGREGATE is available in Excel 2010 and later, including Microsoft 365 and Excel for the web. SUBTOTAL works in every version, so use it if the file must open in Excel 2007 or earlier.