AGGREGATE
Run one of 19 built-in calculations on a range while skipping hidden rows, error values, or nested subtotals.
Spreadsheet editor
Spreadsheet editor
Syntax
=AGGREGATE(function_num, options, ref1, [ref2], ...)
Returns: Number Arguments
| Argument | Required | Description |
|---|---|---|
| function_num | Yes | A number from 1 to 19 that selects which calculation to run: 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 | Yes | A number from 0 to 7 that controls what to skip: 0=ignore nested SUBTOTAL and AGGREGATE results, 1=ignore hidden rows and nested SUBTOTAL and AGGREGATE results, 2=ignore errors and nested SUBTOTAL and AGGREGATE results, 3=ignore hidden rows, errors, and nested SUBTOTAL and AGGREGATE results, 4=ignore nothing, 5=ignore hidden rows, 6=ignore errors, 7=ignore hidden rows and errors. |
| ref1 | Yes | The range or array to calculate. For functions 14-19 (LARGE, SMALL, PERCENTILE, QUARTILE), this is the data array. |
| ref2 | No | A second range for the reference form, or the k value for functions that need a rank or percentile position (LARGE, SMALL, PERCENTILE, QUARTILE). |
About
function_num picks which one to use (9 for SUM, 1 for AVERAGE, 4 for MAX, and so on up to 19 for QUARTILE.EXC). The options value controls what to skip during the calculation: hidden rows, error values like #N/A or #DIV/0!, or nested SUBTOTAL and AGGREGATE functions. In practice, that means if your range includes a cell that already contains =SUBTOTAL(...) or =AGGREGATE(...), options 0-3 can ignore that cell so you do not count a summary result twice.Use AGGREGATE when a regular SUM or AVERAGE would break because your data contains errors, or when you want a result that only counts visible rows after filtering. It handles both scenarios where SUBTOTAL falls short: error skipping and access to statistical functions like LARGE, SMALL, MEDIAN, and PERCENTILE.
Note that functions 14 through 19 (LARGE, SMALL, PERCENTILE.INC, QUARTILE.INC, PERCENTILE.EXC, QUARTILE.EXC) require a second argument,
k, for their rank or percentile position. Also, AGGREGATE is designed for vertical ranges (columns), not horizontal ones (rows).Exercises using AGGREGATE
Examples
SUM fails with errors, AGGREGATE does not
Spreadsheet editor
Six different stats from one column
Spreadsheet editor
Watch out for
AGGREGATE is for columns, not rows
Passing a horizontal range like A1:Z1 gives unreliable results. AGGREGATE is designed to work on vertical data (columns).
→ Structure your data in columns and pass a vertical range like A1:A100. If your data is in rows, transpose it first.
Missing k for LARGE, SMALL, and PERCENTILE functions
Using function_num 14 (LARGE), 15 (SMALL), 16-19 (PERCENTILE and QUARTILE variants) without a second argument returns a #VALUE! error.
→ Add the rank or percentile as the last argument. For example, =AGGREGATE(14, 5, A1:A100, 3) finds the 3rd largest value. The k argument always goes at the end.
Options 0-3 silently skip nested SUBTOTAL results
If your range contains cells with SUBTOTAL formulas, options 0 through 3 ignore them by default. This can cause your total to be lower than expected.
→ Use options 4-7 if you want nested SUBTOTAL or AGGREGATE results included in the calculation. Option 4 ignores nothing at all.
Confusing options values for similar behaviors
Options 1-3 and 5-7 look similar but differ in whether they also skip nested SUBTOTAL/AGGREGATE functions. Getting this wrong leads to subtly incorrect results.
→ Quick reference: use 5 to skip hidden rows only, 6 to skip errors only, 7 to skip both (but still include nested formulas). Use 1, 2, or 3 when you also want nested subtotals excluded.