AGGREGATE function
Calculates SUM, AVERAGE, MAX, LARGE, MEDIAN and 14 other statistics while optionally ignoring errors and hidden rows.
Available in Excel 2010 and later, Excel for the web, Excel for Mac 2011 and later
Excel 2010 and laterNot in Google Sheets
Syntax
AGGREGATE(function_num, options, ref1, [ref2], ...) or AGGREGATE(function_num, options, array, [k])| Argument | What it means | |
|---|---|---|
function_num | Required | 1 AVERAGE, 2 COUNT, 3 COUNTA, 4 MAX, 5 MIN, 6 PRODUCT, 7 STDEV.S, 8 STDEV.P, 9 SUM, 10 VAR.S, 11 VAR.P, 12 MEDIAN, 13 MODE.SNGL, 14 LARGE, 15 SMALL, 16 PERCENTILE.INC, 17 QUARTILE.INC, 18 PERCENTILE.EXC, 19 QUARTILE.EXC. |
options | Required | What to ignore: 0 nested SUBTOTAL/AGGREGATE, 1 + hidden rows, 2 + errors, 3 hidden rows + errors (all include nested), 4 nothing, 5 hidden rows only, 6 errors only, 7 hidden rows and errors. |
ref1 / array | Required | The range to calculate on. Functions 14–19 also accept a calculated array, which is what makes conditional tricks possible. |
k | Optional | For 14–19 only: the position (LARGE/SMALL), percentile or quartile. |
Returns: The requested statistic for the values that are not ignored.
How AGGREGATE works
AGGREGATE is a stronger SUBTOTAL. It offers 19 calculations instead of 11 and, crucially, it can ignore error values. A column with a single #N/A from a failed lookup breaks SUM, MAX and AVERAGE; =AGGREGATE(9, 6, range) simply adds everything else. That makes it ideal for reports built on lookups or imported data that you cannot fully clean.
The second argument decides what to skip: hidden rows, error values, nested SUBTOTAL/AGGREGATE results, or a combination (option 6 = errors only, 7 = errors and hidden rows, 5 = hidden rows only). Functions 1–13 work with references only. Functions 14–19 (LARGE, SMALL, PERCENTILE, QUARTILE) have an array form: you can pass a calculation such as C2:C7/(A2:A7="East"), where non-matching rows become #DIV/0! and option 6 throws them away. This gives a conditional MAX, MIN or k-th largest without Ctrl+Shift+Enter in any version since 2010.
Like SUBTOTAL, AGGREGATE only reacts to hidden rows, not hidden columns. In Microsoft 365 the conditional tricks can also be written with MAXIFS or FILTER, but AGGREGATE remains the simplest way to ignore errors.
Examples
1Sum a column that contains errors
| A | B | |
|---|---|---|
| 1 | Store | Daily sales |
| 2 | Athens | 1840 |
| 3 | Patras | #N/A |
| 4 | Larissa | 1275 |
| 5 | Volos | 990 |
| 6 | Chania | #DIV/0! |
| 7 | Kavala | 1430 |
| 8 | 5,535 |
Result: 5,535
B3 and B6 contain error values from failed lookups. Option 6 skips errors, so the four real figures are added. =SUM(B2:B7) would return #N/A.
2Largest deal in one region (conditional MAX)
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Region | Rep | Deal size | ||
| 2 | East | Ana | 12500 | 21,400 | |
| 3 | West | Ben | 18200 | ||
| 4 | East | Chloe | 21400 | ||
| 5 | North | Dev | 9800 | ||
| 6 | East | Ema | 15900 | ||
| 7 | West | Femi | 11100 |
Result: 21,400
Dividing by the test leaves East deals unchanged and turns other rows into #DIV/0!. LARGE (14) with option 6 ignores those errors and returns the 1st largest East deal: Chloe's 21,400.
3Second smallest value, ignoring errors
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Store | Daily sales | ||
| 2 | Athens | 1840 | 1,275 | |
| 3 | Patras | #N/A | ||
| 4 | Larissa | 1275 | ||
| 5 | Volos | 990 | ||
| 6 | Chania | #DIV/0! | ||
| 7 | Kavala | 1430 |
Result: 1,275
SMALL (15) with k = 2 returns the second lowest valid sales figure. Sorted, the valid values are 990, 1,275, 1,430, 1,840.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#VALUE! | A function number from 1 to 13 is given a calculated array instead of a range, or k is missing for 14–19. | Use 14–19 for array calculations (e.g. 14 with k=1 instead of MAX) and always supply k. |
#NUM! | No values are left after ignoring errors/hidden rows (e.g. LARGE on an empty set), or k is larger than the number of values. | Check the condition and the size of k; wrap in IFERROR if empty results are expected. |
#DIV/0! | AVERAGE (1) when every value is ignored. | Make sure at least one valid number remains. |
Tips
- Remember the most useful pair:
AGGREGATE(9,6,...)for a sum that ignores errors andAGGREGATE(9,7,...)for visible-only totals that also ignore errors. - Use
AGGREGATE(15, 6, ROW(A2:A7)/(A2:A7="East"), n)to get the row of the n-th match, the classic pre-365 way to return multiple lookup results. - Hiding errors can hide problems: check with
=SUMPRODUCT(--ISERROR(range))how many cells are being skipped. - The formula AutoComplete shows the option list when you type the comma after function_num.
Questions
How do I get MAX ignoring errors?
=AGGREGATE(4, 6, range). Function 4 is MAX and option 6 ignores error values.
Does AGGREGATE ignore hidden columns?
No. Like SUBTOTAL it is designed for vertical lists and only skips hidden rows.
Why does AGGREGATE(4,6,C2:C7/(A2:A7="East")) fail?
Functions 1–13 only accept references, not calculated arrays. Use the array form with 14 (LARGE) and k = 1 instead.
Google Sheets
Use SUBTOTAL to ignore hidden rows, or wrap the data in IFERROR/FILTER before SUM, LARGE etc. to ignore errors.
AGGREGATE in other languages
In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.
| Language | Function name |
|---|---|
| Danish | SAMLING |
| Dutch | AGGREGAAT |
| Finnish | KOOSTE |
| French | AGREGAT |
| German | AGGREGAT |
| Hungarian | ÖSSZESÍT |
| Italian | AGGREGA |
| Norwegian (Bokmål) | MENGDE |
| Polish | AGREGUJ |
| Portuguese (Brazil) | AGREGAR |
| Portuguese (Portugal) | AGREGAR |
| Russian | АГРЕГАТ |
| Spanish | AGREGAR |
| Swedish | MÄNGD |
| Turkish | TOPLAMA |
Recipes that use AGGREGATE
- How to average ignoring zeros in Excel
- How to get the nth match in Excel
- How to list the top 5 values with names in Excel
- How to return multiple matches in Excel
- How to sum only visible cells in Excel