AGGREGATE Function in Excel
Master AGGREGATE to perform 19 calculations while ignoring errors, hidden rows, and nested subtotals with practical Excel examples.
=AGGREGATE(function_num, options, ref1, [ref2])Quick Answer
AGGREGATE function AGGREGATE function is an advanced mathematical function in Excel that performs 19 different calculations (SUM, AVERAGE, COUNT, MAX, MIN, and more) while giving you control over which values to ignore. It returns a numeric result and is commonly used for dynamic calculations, handling errors in data, and working with filtered ranges.
=AGGREGATE(function_num, options, ref1, [ref2])- function_num - a number 1-19 selecting the calculation type (9=SUM, 1=AVERAGE, 4=MAX, 5=MIN, etc.)
- options - 0-7 determining what to ignore (errors, hidden rows, or both)
- ref1 - the range or array to calculate on
- ref2 - an optional second argument for functions like LARGE or PERCENTILE
- The basic syntax is `=AGGREGATE(function_num, options, ref1, [ref2])` where: - function_num is a number 1-19 selecting the calculation type (9=SUM, 1=AVERAGE, 4=MAX, 5=MIN, etc.) - options is 0-7 determining what to ignore (errors, hidden rows, or both) - ref1 is the range or array to calculate on - ref2 is an optional second argument for functions like LARGE or PERCENTILE This function excels at robust calculations and typically saves 60% of formula complexity when dealing with errors or filtered data
Practical Examples
Basic SUM with Error Handling
Sum a range of sales values that contains #DIV/0! errors
Average of Visible Rows Only
Calculate average of filtered sales data in an Excel table
Maximum Value Ignoring Errors and Hidden Rows
Find the highest score while handling errors and filtered rows
Count Non-Empty Cells in Filtered Range
Count how many visible entries exist after filtering
Top 3 Values with LARGE Function
Find the 3rd largest sale amount ignoring errors
Dynamic Percentile Calculation
Calculate 90th percentile of response times, excluding errors and hidden rows
Product of Values Excluding Errors
Multiply growth rates together, handling errors gracefully
Common Errors and Solutions
AGGREGATE function returns #VALUE! error
Invalid function_num (not 1-19), invalid options value (not 0-7), or text in numeric range that cannot be ignored with current options
1. Verify function_num is between 1-19: Check you haven't typed 20 or 0 2. Verify options is 0-7: Ensure you're using valid option number 3. Check that ref1 contains numeric data: Text values cause errors even with error-ignoring options 4. Use ISNUMBER or data validation to ensure data quality 5. Test with simpler ranges to isolate the problem cell
Create a reference table with function numbers 1-19 and their meanings. Use data validation on cells containing function_num and options parameters to prevent invalid entries.
Example:
Division by zero in AGGREGATE calculation
Using function_num 1 (AVERAGE), 7-8 (STDEV), or 10-11 (VAR) on an empty range, or a range where all values are ignored by the options parameter
1. Check that your range actually contains visible, valid data after filtering 2. Use option 7 if hidden rows might cause empty result sets 3. Wrap AGGREGATE in IFERROR for graceful handling: =IFERROR(AGGREGATE(...), 0) 4. Pre-validate with COUNT: =IF(AGGREGATE(2,options,range)>0, AGGREGATE(1,options,range), "No data") 5. Verify filters aren't hiding all data rows
Before using AVERAGE-based functions, verify data exists: =IF(AGGREGATE(2,option,range)>0, AGGREGATE(1,option,range), "Insufficient data")
Example:
Numeric error in AGGREGATE result
Invalid ref2 parameter for functions 14-19. Common causes: k value exceeds available values for LARGE/SMALL, percentile not between 0-1, quartile not between 0-4
1. For LARGE/SMALL: Ensure k <= COUNT of available values 2. For PERCENTILE: Verify percentile is between 0 and 1 (0.9 not 90) 3. For QUARTILE: Ensure quartile is 0, 1, 2, 3, or 4 4. Use dynamic k capping: =AGGREGATE(14, 6, range, MIN(3, AGGREGATE(2, 6, range))) 5. Add data validation to prevent invalid inputs
When using functions 14-19, always validate the ref2 parameter. For LARGE/SMALL, cap k at the count of values: MIN(desired_k, AGGREGATE(2,options,range))
Example:
Reference error in AGGREGATE
Deleted cells, rows, or columns that ref1 or ref2 arguments reference. Also occurs when formula is copied to locations where references become invalid
1. Update references to point to valid, existing ranges 2. Use structured references with Excel Tables: Sales[Amount] instead of B2:B100 3. Use named ranges for stability across sheet modifications 4. Check for circular references in dynamic ranges 5. Verify sheet names in cross-sheet references are correct
Always use Excel Tables with structured references or named ranges for AGGREGATE formulas. These automatically adjust when rows/columns are inserted or deleted, preventing #REF! errors.
Example:
Advanced Tips and Best Practices
Master the Options Parameter - Your Key to Flexibility
Options 5, 6, and 7 handle 95% of real-world scenarios. Option 5 (ignore hidden rows) is perfect for filtered Excel tables and dashboards where users control visibility. Option 6 (ignore errors) excels with imported data or formula-heavy sheets prone to occasional errors. Option 7 (ignore both) provides maximum robustness for production reports that must work under all conditions. Start with option 7 in new reports, then optimize to 5 or 6 if performance is critical.
Replace SUBTOTAL with AGGREGATE for More Power
AGGREGATE offers 19 functions versus SUBTOTAL's 11, plus more granular control over what to ignore. When building new workbooks, default to AGGREGATE instead of SUBTOTAL. The syntax is similar: =AGGREGATE(9,5,range) replaces =SUBTOTAL(109,range) for summing visible cells, but AGGREGATE also offers MEDIAN, MODE, PERCENTILE, and other functions SUBTOTAL lacks.
Combine with Excel Tables for Dynamic Excellence
Use structured references with AGGREGATE for formulas that automatically adjust to data changes: =AGGREGATE(1,5,Sales[Revenue]) calculates the average of visible revenue in the Sales table, auto-expanding as new rows are added. This combination provides industrial-strength formulas that require minimal maintenance and are self-documenting.
Create Dynamic Top N Lists Without Helper Columns
Use AGGREGATE with LARGE or SMALL functions to extract top N values dynamically. Combine with IFERROR and ROW to create spilling lists: =IFERROR(AGGREGATE(14,6,DataRange,ROW(A1)),""). Copy down to get top 1, top 2, top 3, etc. This eliminates complex array formulas and helper columns while remaining easy to understand and modify.
Performance Considerations with Large Datasets
AGGREGATE recalculates whenever source data changes. With datasets exceeding 50,000 rows, you may notice calculation lag, especially when using functions 14-19 which require sorting. For very large datasets (100K+ rows), consider: (1) Converting to values periodically, (2) Using Power Query for transformations, or (3) Implementing calculation on demand with Manual calculation mode (Formulas > Calculation Options > Manual).
Not Available in Google Sheets
Google Sheets doesn't have AGGREGATE function. When sharing workbooks cross-platform, provide alternatives: Use SUBTOTAL for filtered data (limited to 11 functions), or combinations like =SUM(FILTER(range, NOT(ISERROR(range)))) for error handling. Document these differences clearly for users switching between platforms.
Create a Function Number Reference
Memorizing all 19 function numbers is challenging. Create a small reference table in your workbook or use an Excel comment: 1=AVG, 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, 14=LARGE, 15=SMALL, 16=PERCENTILE.INC, 17=QUARTILE.INC, 18=PERCENTILE.EXC, 19=QUARTILE.EXC. Remember: functions 1-13 need only ref1, functions 14-19 require ref2.
Use Cell References for Dynamic Function Selection
Instead of hardcoding function_num, reference a cell: =AGGREGATE(A1,5,DataRange). This allows users to select calculations from a dropdown without editing formulas. Combine with data validation (1-19) and a lookup table showing function names, creating user-friendly, flexible analysis tools.
Need Help with AGGREGATE Function in Excel?
Stop struggling with formula syntax. Use AskFormulas to generate validated formulas instantly with our AI-powered tool.
Example Excel formula: