Skip to content

AGGREGATE

Runs a calculation such as sum, average, large or median over a range, with options to skip errors, hidden rows and nested subtotals.

Syntax

=AGGREGATE(, , , [ref2], …)

Math and trigonometry

Excel 2010 and later, including Excel for Microsoft 365 and Excel for the web.

Try it

Edit the formula in B8 or change the inputs. The sheet recalculates as you type.

B8
A
B
1
Branch
Weekly sales
2
Leeds
1,840
3
Hull
2,210
4
York
#N/A
5
Bath
1,975
6
Derby
2,430
7
8
Total
8,455

B8 =AGGREGATE(9,6,B2:B6) returns 8455

How AGGREGATE works

AGGREGATE does what SUBTOTAL does and more. It offers 19 calculations, including median, large, small and percentiles, and an options argument that lets you ignore error values. That last feature is why people reach for it: a single #N/A in a column turns SUM, AVERAGE and MAX into errors, while AGGREGATE can step over it.

Two forms

For functions 1 to 13 you give a range or several ranges: =AGGREGATE(9, 6, B2:B9) sums the numbers in B2:B9 and ignores errors, because option 6 means "ignore error values".

For functions 14 to 19 the second reference is a value: =AGGREGATE(14, 6, B2:B9, 2) returns the second-largest number, ignoring errors. In this form the range can be an array expression.

The options argument

| Option | Ignores | |---|---| | 0 or omitted | nested SUBTOTAL and AGGREGATE | | 1 | also hidden rows | | 2 | also error values | | 3 | hidden rows and error values | | 4 | nothing | | 5 | hidden rows | | 6 | error values | | 7 | hidden rows and error values |

Option 6 is the one you will use most often. Options 0 to 3 skip nested SUBTOTAL and AGGREGATE results, like SUBTOTAL, so a subtotal row won't be counted twice.

Conditional maximum and minimum

Functions 14 to 19 accept array expressions, which makes a conditional largest or smallest value possible without MAXIFS: =AGGREGATE(14, 6, B2:B9/(A2:A9="North"), 1). Dividing by FALSE (0) produces #DIV/0! for every non-North row, and option 6 ignores those errors, leaving the largest North value.

AGGREGATE compared with its neighbours

  • SUBTOTAL has fewer calculations and can't skip errors.
  • SUM and the other single functions return the first error they meet.
  • IFERROR can hide an error for one cell, but not for a whole range.

Watch two limits. The reference form, functions 1 to 13, needs a range, not an array. And hidden-row options apply to rows only: hiding a column has no effect.

Arguments

function_num
Which calculation to run, 1 to 19. 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
What to ignore. 0 or omitted: nested SUBTOTAL and AGGREGATE. 1: also hidden rows. 2: also error values. 3: hidden rows and errors. 4: nothing. 5: hidden rows. 6: error values. 7: hidden rows and error values.
ref1
The range to calculate over. For functions 14 to 19 it can also be an array, such as B2:B9/(A2:A9="North").
ref2, …optional
For functions 1 to 13, more ranges. For functions 14 to 19, the value k or the percentile or quartile, such as 2 for the second largest.

Examples

Each example is a live sheet. Change the inputs or the formula and watch the result.

Example 1

Sum a column that contains an error

B8 =AGGREGATE(9,6,B2:B6)

Result: 8455

York has not reported, so B4 is #N/A. SUM(B2:B6) would return #N/A. Option 6 steps over the error and adds the other four.

B8
A
B
1
Branch
Weekly sales
2
Leeds
1,840
3
Hull
2,210
4
York
#N/A
5
Bath
1,975
6
Derby
2,430
7
8
Total
8,455

B8 =AGGREGATE(9,6,B2:B6) returns 8455

Example 2

Second-largest value, ignoring errors

B8 =AGGREGATE(14,6,B2:B6,2)

Result: 2210

Function 14 is LARGE, so the last argument is k. The sorted numbers are 2,430, 2,210, 1,975 and 1,840.

B8
A
B
1
Branch
Weekly sales
2
Leeds
1,840
3
Hull
2,210
4
York
#N/A
5
Bath
1,975
6
Derby
2,430
7
8
2nd best
2,210

B8 =AGGREGATE(14,6,B2:B6,2) returns 2210

Example 3

Smallest value, ignoring errors

B8 =AGGREGATE(5,6,B2:B6)

Result: 1840

Function 5 is MIN. With option 6 the error in B4 is skipped.

B8
A
B
1
Branch
Weekly sales
2
Leeds
1,840
3
Hull
2,210
4
York
#N/A
5
Bath
1,975
6
Derby
2,430
7
8
Lowest
1,840

B8 =AGGREGATE(5,6,B2:B6) returns 1840

Example 4

Conditional maximum without MAXIFS

B8 =AGGREGATE(14,6,B2:B6/(A2:A6="North"),1)

Result: 200

Dividing by the test turns every non-North row into #DIV/0!. Option 6 ignores those, so LARGE sees only 120, 200 and 95.

B8
A
B
C
1
Region
Value
2
North
120
3
South
80
4
North
200
5
South
50
6
North
95
7
8
Best North
200

B8 =AGGREGATE(14,6,B2:B6/(A2:A6="North"),1) returns 200

Example 5

Median ignoring nothing (option 4)

B8 =AGGREGATE(12,4,B2:B6)

Result: 95

Function 12 is MEDIAN and option 4 ignores nothing. The middle of 50, 80, 95, 120 and 200 is 95.

B8
A
B
1
Order
Value
2
A-1
120
3
A-2
80
4
A-3
200
5
A-4
50
6
A-5
95
7
8
Median
95

B8 =AGGREGATE(12,4,B2:B6) returns 95

Your turn.

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In B9, total the weekly sales for the branches that have reported. One cell holds an error.

Answer in B9.

B9
A
B
C
1
Branch
Weekly sales
2
Leeds
1,840
3
Hull
2,210
4
York
#N/A
5
Bath
1,975
6
Derby
2,430
7
Exeter
1,560
8
9
Total reported
10
2nd lowest

Common mistakes

  • Functions 1 to 13 need a range in the reference form. An array expression such as B2:B9/(A2:A9="North") only works with functions 14 to 19.
  • Option 4, "ignore nothing", still returns the first error in the range. People often pick it expecting errors to be skipped; that needs 2, 3, 6 or 7.
  • Ignoring errors can hide a real problem such as a broken lookup. Check where the errors come from before you suppress them.
  • For functions 14 to 19 the last argument is k (or the percentile), not another range. Leaving it out returns #VALUE!.
  • Hidden-row options affect rows only. Hiding a column doesn't change the result.

Questions people ask

How do I sum a range that contains errors?

Use `=AGGREGATE(9, 6, B2:B9)`. Function 9 is SUM and option 6 ignores error values. Plain SUM would return the first error it finds.

What is the difference between AGGREGATE and SUBTOTAL?

AGGREGATE has 19 calculations instead of 11, can ignore error values, and accepts array expressions for LARGE, SMALL and percentiles. SUBTOTAL is simpler and works in every Excel version.

What does option 6 mean in AGGREGATE?

It tells AGGREGATE to ignore error values. It doesn't skip hidden rows. Option 7 skips both hidden rows and errors.

Can AGGREGATE do a conditional MAX or MIN?

Yes. Use function 14 or 15 with an array that divides by the condition, for example `=AGGREGATE(14, 6, B2:B9/(A2:A9="North"), 1)`. In Microsoft 365, MAXIFS and MINIFS are simpler.

Does AGGREGATE work in older versions of Excel?

It was added in Excel 2010. In Excel 2007 and earlier the formula returns `#NAME?`.

Learn AGGREGATE in a real sheet.

AGGREGATE is taught in Data analysis with formulas, lesson 19: AGGREGATE: ignore errors. Each lesson is a short, graded exercise like the one above.