AGGREGATE: The Swiss Army Knife of Excel Functions

AGGREGATE function in Excel — showing a table where SUM fails on a #DIV/0! error but AGGREGATE(9,6,...) returns 7,850 by skipping the error cell, with the 8-option reference table, AGGREGATE-only functions list (MEDIAN, LARGE, PERCENTILE), and five key formula examples.
SUBTOTAL handles 11 aggregation types. AGGREGATE handles 19 — and it ignores errors. It does everything SUBTOTAL does, then adds MEDIAN, LARGE, SMALL, PERCENTILE, and QUARTILE to the same filter-aware framework. When a #DIV/0! in one cell breaks your SUBTOTAL total, AGGREGATE skips it. When you need the median of filtered data — which SUBTOTAL cannot compute — AGGREGATE delivers it with a single formula. This guide covers both syntax forms, all 19 function numbers, all 8 option codes, and six practical examples: error-tolerant SUM and AVERAGE, filter-aware MEDIAN and five-number summary, k-th LARGE and SMALL on filtered data, PERCENTILE and IQR outlier bounds, a trimmed mean that removes extreme outliers before averaging, and visible-row RANK. It also explains the most important option choice: use option 5 for most filtered tables, option 7 when data also contains errors, and options 0–3 in grouped reports to prevent grand totals from double-counting group subtotals.

SUBTOTAL handles 11 aggregation types. AGGREGATE handles 19 — and it ignores errors. It does everything SUBTOTAL does, then adds MEDIAN, LARGE, SMALL, PERCENTILE, QUARTILE, and RANK to the same filter-aware framework. The options argument gives precise control over what to exclude: filtered rows, hidden rows, nested aggregates, errors, or any combination. When a formula fails because of a #DIV/0! in one cell, or because you need the median of filtered data, AGGREGATE is the answer.

This guide covers both syntax forms, all 19 function numbers, all 8 option codes, and six practical examples. You will learn how to compute filter-aware medians and percentiles, extract the k-th largest visible value, handle error-contaminated ranges, and build an outlier-aware average. Each example also shows when AGGREGATE has a distinct advantage over its SUBTOTAL equivalent.

Availability: AGGREGATE is available from Excel 2010 onward, including Microsoft 365, Excel 2024, 2021, 2019, and 2016. It is not available in Google Sheets. SUBTOTAL remains the correct choice for Google Sheets compatibility. AGGREGATE does not require array entry in any version — it always enters as a standard formula.

What Makes AGGREGATE Different from SUBTOTAL?

SUBTOTAL ignores filtered and hidden rows, and skips nested SUBTOTAL results. AGGREGATE does all of that and adds two major capabilities. First, it can ignore error values in the data range. A single #DIV/0! or #VALUE! in the range breaks SUBTOTAL — it propagates the error to the result. AGGREGATE skips those cells and computes the result on the remaining valid values. Second, AGGREGATE supports eight additional aggregation functions that SUBTOTAL does not offer.

The options argument is the key that unlocks these capabilities. It is a number from 0 to 7 that specifies exactly which rows to exclude. Options 0–3 control hidden row and error behaviour. Options 4–7 add the ability to ignore nested SUBTOTAL and AGGREGATE results on top of the other exclusions. Choosing the right option is the most important decision when using AGGREGATE.

What Is the AGGREGATE Syntax?

AGGREGATE has two syntax forms. The first (list form) works like SUBTOTAL — pass a range reference and get an aggregate over the entire range. The second (array form) enables LARGE, SMALL, PERCENTILE, and QUARTILE by accepting an array expression with an optional k argument. Always use the array form when the function number requires k.

List form — for SUM, COUNT, AVERAGE, MAX, MIN, MEDIAN, STDEV, VAR, etc.: =AGGREGATE(function_num, options, ref1, [ref2], ...) Array form — for LARGE, SMALL, PERCENTILE, QUARTILE, RANK: =AGGREGATE(function_num, options, array, [k])
ArgumentRequired?What it does
function_numRequiredA number from 1 to 19 specifying the aggregation type. See the full table below.
optionsRequiredA number from 0 to 7 controlling which rows to ignore. This is the key difference from SUBTOTAL.
ref1 / arrayRequiredThe data range (list form) or array expression (array form).
kConditionalRequired for LARGE (fn 14), SMALL (fn 15), PERCENTILE.INC (fn 16), QUARTILE.INC (fn 17), PERCENTILE.EXC (fn 18), QUARTILE.EXC (fn 19). Not used for other function numbers.

What Are the AGGREGATE Function Numbers and Options?

Fn #FunctionSUBTOTAL equivalent?Notes
1AVERAGEYes (fn 1/101)
2COUNTYes (fn 2/102)
3COUNTAYes (fn 3/103)
4MAXYes (fn 4/104)
5MINYes (fn 5/105)
6PRODUCTYes (fn 6/106)
7STDEV.SYes (fn 7/107)Sample std dev
8STDEV.PYes (fn 8/108)Population std dev
9SUMYes (fn 9/109)
10VAR.SYes (fn 10/110)Sample variance
11VAR.PYes (fn 11/111)Population variance
12MEDIAN✗ AGGREGATE only
13MODE.SNGL✗ AGGREGATE onlyMost frequent value
14LARGE✗ AGGREGATE onlyRequires k
15SMALL✗ AGGREGATE onlyRequires k
16PERCENTILE.INC✗ AGGREGATE onlyk = 0 to 1
17QUARTILE.INC✗ AGGREGATE onlyk = 0 to 4
18PERCENTILE.EXC✗ AGGREGATE onlyk = 0 to 1 exclusive
19QUARTILE.EXC✗ AGGREGATE onlyk = 1 to 3
OptionIgnores
0Nested SUBTOTAL and AGGREGATE functions only
1Hidden rows + nested SUBTOTAL/AGGREGATE
2Error values + nested SUBTOTAL/AGGREGATE
3Hidden rows + error values + nested SUBTOTAL/AGGREGATE
4Nothing (no exclusions at all)
5Hidden rows only
6Error values only
7Hidden rows + error values
Which option to use: For filter-aware totals, use option 5 (hidden rows) or option 3 (hidden rows + errors). Option 5 is the most common choice for filtered tables. Options 0–3 also skip nested AGGREGATE and SUBTOTAL results — useful in grouped reports. Options 4–7 do not skip nested results, which means grand totals may double-count group subtotals. When in doubt, option 5 is a safe default for most filter-aware aggregations.

Examples 1–4: Core AGGREGATE Patterns

1
Error-tolerant SUM and AVERAGE — skip #DIV/0! and #VALUE! cells

A column that contains formula errors blocks any standard aggregation. IFERROR wrapping on every cell is tedious and can mask genuine problems. AGGREGATE with option 6 or 7 processes valid cells and skips error cells entirely. This is one of AGGREGATE’s most practical advantages over both SUM and SUBTOTAL.

Cell
Value
SUM result
AGGREGATE result
A2
1,200
#DIV/0!
7,850
A3
#DIV/0!
(error
(3 cells
A4
3,150
propagates)
summed)
A5
#VALUE!
A6
3,500
A2:A10 = values including some #DIV/0! and #VALUE! errors. SUM returns an error if any cell in range has an error: =SUM(A2:A10) → #DIV/0! (propagates the first error it finds) AGGREGATE option 6 — ignore error values, include all rows: Computes the sum of valid (non-error) cells only. =AGGREGATE(9, 6, A2:A10) → 7,850 (sum of the 3 non-error cells: 1200 + 3150 + 3500) AGGREGATE option 7 — ignore hidden rows AND errors (most useful for filtered tables): This is the most complete option for filtered tables with error-prone formulas. =AGGREGATE(9, 7, A2:A10) → Same result when no filter active. Updates when filter hides rows. Error-tolerant AVERAGE — average of non-error visible cells: function_num 1 = AVERAGE. option 7 = hidden rows + errors ignored. =AGGREGATE(1, 7, A2:A10) → 2,617 (average of the 3 valid, visible cells: 7850 / 3) Count of non-error, visible cells — useful for denominator verification: function_num 2 = COUNT. option 7 = ignore hidden and errors. =AGGREGATE(2, 7, A2:A10) → 3 (only 3 cells are both visible and non-error)
2
Filter-aware MEDIAN — the statistic SUBTOTAL cannot compute

MEDIAN is one of the most requested statistics in filtered tables, and SUBTOTAL cannot produce it. AGGREGATE function number 12 fills this gap. When a filter is applied, AGGREGATE(12, 5, ...) returns the median of visible rows only, updating as the filter changes. This is also the most practical advantage AGGREGATE has over SUBTOTAL in day-to-day analysis.

C2:C100 = revenue column in a filtered sales table. Filter active: Region = "North" (showing 18 of 100 rows). Filter-aware MEDIAN — median of visible rows: option 5 = ignore hidden rows (the filter hides the non-North rows). =AGGREGATE(12, 5, C2:C100) → Median revenue for North region only (updates when filter changes) Compare median to SUBTOTAL average — spot skewed distributions: D2 = AGGREGATE median. E2 = SUBTOTAL(1) average. A large gap indicates the data is skewed (outliers pulling the mean). D2 - E2 → Positive = median > mean (left-skewed). Negative = mean > median (right-skewed). MODE of visible rows — function number 13: Most frequently occurring value among visible rows. =AGGREGATE(13, 5, C2:C100) → Most common revenue value in the filtered view Full five-number summary of visible rows: Combine AGGREGATE calls for min, Q1, median, Q3, max. Min: =AGGREGATE(5, 5, C2:C100) Q1: =AGGREGATE(17, 5, C2:C100, 1) Median: =AGGREGATE(12, 5, C2:C100) Q3: =AGGREGATE(17, 5, C2:C100, 3) Max: =AGGREGATE(4, 5, C2:C100)
3
LARGE and SMALL — k-th ranked value in filtered or error-containing data

LARGE and SMALL normally break when errors are present in the range. AGGREGATE with function numbers 14 and 15 handles this cleanly. Specifically, it returns the k-th largest or smallest value from visible, non-error cells only. Specifically, this is useful for top-N reports on filtered tables, where you want the k-th best deal on screen rather than from the full dataset.

C2:C100 = revenue values (some may be errors or in filtered-out rows). k = 1 for the largest, 2 for the second largest, and so on. 3rd largest visible revenue (array form — k is the 4th argument): function_num 14 = LARGE. option 5 = ignore hidden rows. =AGGREGATE(14, 5, C2:C100, 3) → 3rd largest revenue among visible rows 3rd smallest visible revenue: function_num 15 = SMALL. option 5 = ignore hidden rows. =AGGREGATE(15, 5, C2:C100, 3) → 3rd smallest revenue among visible rows Top-3 summary table — in cells D2, D3, D4: D2 = 1st largest, D3 = 2nd largest, D4 = 3rd largest. E2 = the row position of the result (for reference): Use MATCH on the AGGREGATE result to find which row it came from. =AGGREGATE(14, 5, C2:C100, ROW()-ROW($D$2)+1) → Enter in D2, copy down — k auto-increments: 1 in D2, 2 in D3, 3 in D4 Error-tolerant LARGE (ignore errors in data, no filter): option 6 = ignore errors only. Useful when rows are not filtered but data has errors. =AGGREGATE(14, 6, C2:C100, 1) → Largest non-error value in the column regardless of filter
4
PERCENTILE and QUARTILE — distribution analysis on filtered data

Percentile and quartile calculations on filtered data are impossible with standard PERCENTILE.INC or QUARTILE.INC functions, which always consider the full range regardless of filter status. AGGREGATE function numbers 16–19 solve this. They compute percentiles and quartiles from visible rows only, making them the correct tool for distribution reporting on filtered datasets.

C2:C100 = salary data. Filter active: Department = "Engineering". k for PERCENTILE = a decimal from 0 to 1 (e.g. 0.9 = 90th percentile). k for QUARTILE = an integer 0–4 (1=Q1, 2=Q2, 3=Q3). 90th percentile of Engineering salaries (filtered view): function_num 16 = PERCENTILE.INC. option 5 = ignore hidden rows. =AGGREGATE(16, 5, C2:C100, 0.9) → 90th percentile salary for Engineering, updates with filter Q1, Q3, and IQR of visible rows: function_num 17 = QUARTILE.INC. k=1 for Q1, k=3 for Q3. =AGGREGATE(17, 5, C2:C100, 1) ← Q1 =AGGREGATE(17, 5, C2:C100, 3) ← Q3 IQR (Q3 − Q1): =AGGREGATE(17,5,C2:C100,3) - =AGGREGATE(17,5,C2:C100,1) → IQR of visible Engineering salaries IQR outlier bounds — values beyond 1.5×IQR from Q1/Q3: Lower bound = Q1 − 1.5 × IQR. Upper bound = Q3 + 1.5 × IQR. F2 - 1.5 * F3 ← lower outlier fence (F2=Q1, F3=IQR) F4 + 1.5 * F3 ← upper outlier fence (F4=Q3)

Examples 5 and 6: Advanced AGGREGATE Patterns

Outlier-Robust Averages and Rank on Visible Data

5
Trimmed mean — outlier-robust average using AGGREGATE

A standard average is sensitive to outliers. One extremely high or low value can pull the mean far from the centre of the data. A trimmed mean removes the top and bottom k values before averaging, producing a more robust measure of centre. Building one with AGGREGATE combines LARGE, SMALL, and SUM — working on filtered data and tolerating errors.

C2:C50 = 49 revenue values (some may be extreme outliers). Trimmed mean: remove the top 2 and bottom 2 values, then average the rest. Step 1: Sum of all visible, non-error values: D2 = total sum. =AGGREGATE(9, 7, C2:C50) Step 2: Remove top 2 outliers (subtract the 2 largest values): D3 = sum of top 2 (AGGREGATE LARGE, k=1 and k=2). =AGGREGATE(14, 7, C2:C50, 1) + =AGGREGATE(14, 7, C2:C50, 2) Step 3: Remove bottom 2 outliers (subtract the 2 smallest values): D4 = sum of bottom 2 (AGGREGATE SMALL, k=1 and k=2). =AGGREGATE(15, 7, C2:C50, 1) + =AGGREGATE(15, 7, C2:C50, 2) Step 4: Count of non-error, visible values: D5 = n (number of valid visible cells). =AGGREGATE(2, 7, C2:C50) Trimmed mean — combine all steps: (total − top 2 − bottom 2) / (n − 4) (D2 - D3 - D4) / (D5 - 4) → Trimmed mean excludes extreme outliers, updates with filter, skips errors
Compare the trimmed mean to the standard AGGREGATE AVERAGE. A large gap confirms outliers are distorting the mean. Use it for salary benchmarks, compensation analysis, and any dataset where extreme values represent unusual conditions.
6
Visible-row RANK — rank values among currently shown rows only

The standard RANK function ranks a value against all rows, ignoring filters. Consequently, a filtered row’s rank reflects its position in the full dataset — not among the visible rows. Specifically, combining AGGREGATE LARGE with COUNTIF on the visible range produces a rank for the current filtered view.

C2:C100 = revenue values. Filter active (showing a subset of rows). Goal: show each visible row’s rank within the currently visible rows. Standard RANK ignores the filter: =RANK(C2, C2:C100) → ranks C2 against ALL 100 rows (wrong when filtered) Visible-row rank using AGGREGATE LARGE: Count how many visible values are >= C2 (i.e. how many are ranked higher). Then add 1 to get the rank. Enter in D2 and copy down to D100: AGGREGATE(14, 5, C2:C100, k) returns the k-th largest visible value. COUNTIF counts how many visible-largest values exceed C2. =SUMPRODUCT( (=AGGREGATE(14, 5, C2:C100, ROW(INDIRECT("1:"&=AGGREGATE(2,5,C2:C100))) )) > C2 ) + 1 → Rank of C2 within visible rows only (1 = highest) Simpler approach — use the visibility helper column (H2:H100 = SUBTOTAL(103,A2)): COUNTIFS with the visibility column avoids complex SUMPRODUCT. =COUNTIFS(C2:C100, ">"&C2, H2:H100, 1) + 1 → Same visible-row rank, using visibility helper H = SUBTOTAL(103, A2)

Common Issues and How to Fix Them

AGGREGATE returns #VALUE! even with error options

AGGREGATE options 2, 3, 6, and 7 ignore error values — but only in the data cells, not in the arguments themselves. If function_num or options contains an error, AGGREGATE still returns an error. Also check that you are using the correct syntax form. Specifically, LARGE, SMALL, PERCENTILE, and QUARTILE require the array form with four arguments, not three. Calling =AGGREGATE(14, 5, C2:C100) without the k argument returns #VALUE! because k is missing.

The result does not change when I apply a filter

AGGREGATE responds to AutoFilter (Data → Filter or Table filters). Options 1, 3, 5, and 7 ignore hidden rows. However, if Automatic Calculation is off (Formulas → Calculation Options → Manual), AGGREGATE does not recalculate when the filter changes. Press F9 to force recalculation, or switch back to Automatic Calculation. Also confirm that option 5 or 7 is chosen — options 0, 2, 4, and 6 do not exclude hidden rows.

AGGREGATE double-counts grouped subtotals in a grand total

Options 4–7 do not skip nested SUBTOTAL or AGGREGATE results. If a column contains group subtotal rows and a grand total references the entire column, options 4–7 count those subtotal rows as data. Instead, use options 0–3 for grand totals — those automatically skip nested AGGREGATE and SUBTOTAL values.

AGGREGATE is not available in Google Sheets: AGGREGATE is an Excel-only function. If your workbook must work in Google Sheets, use SUBTOTAL instead. For MEDIAN and PERCENTILE in Google Sheets, use array formulas with FILTER or IF. The SUBTOTAL function works identically in Google Sheets and all Excel versions.

Frequently Asked Questions

  • What does the AGGREGATE function do?+
    AGGREGATE performs 19 different aggregation operations — including SUM, AVERAGE, COUNT, MAX, MIN, MEDIAN, LARGE, SMALL, PERCENTILE, and QUARTILE — with the ability to ignore filtered rows, manually hidden rows, error values, and nested SUBTOTAL or AGGREGATE results. It is the extended version of SUBTOTAL, available from Excel 2010 onward. The key advantage over SUBTOTAL is the additional functions (12–19) and the error-tolerance option. The key advantage over SUM and MEDIAN is filter-awareness — AGGREGATE considers only visible rows when the appropriate option is set.
  • What is the difference between AGGREGATE and SUBTOTAL?+
    SUBTOTAL supports 11 aggregation functions (AVERAGE, COUNT, COUNTA, MAX, MIN, PRODUCT, STDEV, STDEVP, SUM, VAR, VARP). AGGREGATE supports all 11 of those plus 8 more: MEDIAN, MODE, LARGE, SMALL, PERCENTILE.INC, QUARTILE.INC, PERCENTILE.EXC, and QUARTILE.EXC. AGGREGATE also adds an options argument for controlling error handling, which SUBTOTAL does not have. Both work in Excel 2010 and later. SUBTOTAL also works in Google Sheets; AGGREGATE does not. For most filter-aware totals, either works. Use AGGREGATE specifically when you need MEDIAN, LARGE, SMALL, PERCENTILE, or error-tolerant aggregation.
  • Which AGGREGATE option should I use?+
    For filtered tables where you want filter-aware results, use option 5 (ignore hidden rows). This is the most common choice for everyday dashboards and report totals. If your data also contains formula errors, use option 7 (ignore hidden rows and errors) to handle both simultaneously. In grouped reports with nested AGGREGATE or SUBTOTAL rows, use options 0–3 to prevent double-counting in grand totals. Options 4–7 do not skip nested results. For a clean default that works in most situations, option 5 is the recommended starting point.

More Questions About AGGREGATE

  • Can AGGREGATE replace IFERROR?+
    For aggregation purposes, yes. Instead of wrapping every cell with IFERROR, use AGGREGATE with option 6 or 7 to ignore errors. For example, =AGGREGATE(9, 6, A2:A100) sums the range and skips any error cells, returning the total of the valid values. This is cleaner and more efficient than =SUMPRODUCT(IFERROR(A2:A100, 0)). However, AGGREGATE only works for the 19 supported aggregation types. If you need a non-aggregation formula to handle an individual error, IFERROR or ISNUMBER+IF is still the right approach.
  • How do I use AGGREGATE for LARGE on filtered data?+
    Use function_num 14 with option 5 and provide k as the fourth argument: =AGGREGATE(14, 5, C2:C100, 1) for the largest visible value, =AGGREGATE(14, 5, C2:C100, 2) for the second largest, and so on. This is the array form of AGGREGATE — the k argument appears after the range. It returns the k-th largest value from currently visible rows, skipping error cells if option 6 or 7 is set. For a dynamic top-3 table, enter in D2 with ROW()-ROW($D$2)+1 as k and copy down three rows.
  • Does AGGREGATE work with Excel Tables?+
    Yes. AGGREGATE works with structured table references just like SUBTOTAL. Reference the column using the table column notation: =AGGREGATE(9, 5, SalesData[Revenue]) for a filter-aware SUM of the Revenue column. The Total Row uses SUBTOTAL by default, but you can replace those formulas with AGGREGATE to gain MEDIAN, LARGE, or error-tolerance. Additionally, when new rows are added, the AGGREGATE range expands automatically via the structured reference.