Math & trig function

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])
ArgumentWhat it means
function_numRequired1 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.
optionsRequiredWhat 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 / arrayRequiredThe range to calculate on. Functions 14–19 also accept a calculated array, which is what makes conditional tricks possible.
kOptionalFor 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

B8fx=AGGREGATE(9, 6, B2:B7)
AB
1StoreDaily sales
2Athens1840
3Patras#N/A
4Larissa1275
5Volos990
6Chania#DIV/0!
7Kavala1430
85,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)

E2fx=AGGREGATE(14, 6, C2:C7/(A2:A7="East"), 1)
ABCDE
1RegionRepDeal size
2EastAna1250021,400
3WestBen18200
4EastChloe21400
5NorthDev9800
6EastEma15900
7WestFemi11100

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

D2fx=AGGREGATE(15, 6, B2:B7, 2)
ABCD
1StoreDaily sales
2Athens18401,275
3Patras#N/A
4Larissa1275
5Volos990
6Chania#DIV/0!
7Kavala1430

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.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 17 KB

Common errors and how to fix them

ErrorWhy it happensFix
#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 and AGGREGATE(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.

LanguageFunction name
DanishSAMLING
DutchAGGREGAAT
FinnishKOOSTE
FrenchAGREGAT
GermanAGGREGAT
HungarianÖSSZESÍT
ItalianAGGREGA
Norwegian (Bokmål)MENGDE
PolishAGREGUJ
Portuguese (Brazil)AGREGAR
Portuguese (Portugal)AGREGAR
RussianАГРЕГАТ
SpanishAGREGAR
SwedishMÄNGD
TurkishTOPLAMA

Recipes that use AGGREGATE