Returns an aggregate in a list or database by choosing from 19 available aggregation functions. Ignores hidden rows, error values, and SUBTOTAL results.
Master the fundamentals of Excel AGGREGATE function
The AGGREGATE function provides a flexible way to perform 19 different types of aggregation (AVERAGE, COUNT, MAX, MIN, PERCENTILE, etc.) while automatically handling error values, hidden rows, and nested SUBTOTAL/AGGREGATE functions. This makes it more robust than standard aggregation functions, especially when dealing with dirty data or filtered lists.
Supports AVERAGE, COUNT, COUNTA, MAX, MIN, LARGE, SMALL, PERCENTILE, QUARTILE, STDDEV, VAR, and more
Automatically ignores #N/A, #VALUE!, #DIV/0!, #REF!, #NUM!, #NAME?, or #NULL! errors
Optional capability to include or exclude hidden rows from calculations
Can ignore results from nested SUBTOTAL/AGGREGATE functions to prevent double-counting
Function-specific parameters
Function-specific return type
Calculate statistics on visible rows in filtered data
Perform aggregations on data containing error values
Create flexible reports with nested SUBTOTAL functions
Calculate percentiles, quartiles, and rank statistics
Exact matching required
Returns numeric position
Handles missing text gracefully
=AGGREGATE(function_num, options, array, k)A number 1-19 that specifies which aggregation function to use (1=AVERAGE, 2=COUNT, 3=COUNTA, etc.)
A number 0-7 that specifies which values to ignore (0 or omitted: ignore nested SUBTOTAL/AGGREGATE, 1: ignore hidden rows, 2: ignore error values, etc.)
An array, array formula, or reference to cells for aggregation
A second argument required for SMALL, LARGE, PERCENTILE, or QUARTILE functions
Result from the specified aggregation function
Description: Aggregates data while ignoring errors, hidden rows, and nested subtotals
Calculate average while ignoring #DIV/0! errors
Uses AVERAGE (1), ignores errors (6), returns 25
Simple VBA implementation
Sub UseAggregate()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet1")
' Example 1: Average ignoring errors (function 1, option 6)
ws.Range("C1").Value = Application.WorksheetFunction.Aggregate(1, 6, ws.Range("A1:A10"))
' Example 2: Count visible rows (function 3, option 5)
ws.Range("C2").Value = Application.WorksheetFunction.Aggregate(3, 5, ws.Range("A1:A20"))
' Example 3: Find third largest value (function 14, k=3)
ws.Range("C3").Value = Application.WorksheetFunction.Aggregate(14, 0, ws.Range("A1:A20"), 3)
End SubCalculate on visible filtered rows
Aggregate data with errors
Calculate percentiles for rankings
Avoid double-counting in subtotals
Invalid function_num or options argument
Check function_num and options valuesSolution: Ensure function_num is 1-19 and options is 0-7. Use AGGREGATE(1,6,range) format.
Not ignoring expected values
Adjust options parameterSolution: Verify options parameter. 6 ignores errors only, need 7 for all options.
Function requires k parameter
Use: AGGREGATE(14, 0, range, 3)Solution: Add k argument for SMALL(15), LARGE(14), PERCENTILE(16), QUARTILE(17)