AGGREGATE Function in Excel

Master AGGREGATE to perform 19 calculations while ignoring errors, hidden rows, and nested subtotals with practical Excel examples.

ExcelExcel
Google SheetsGoogle Sheets
math
advanced
Syntax Preview
ExcelExcel
=AGGREGATE(function_num, options, ref1, [ref2])
Comprehensive Explanation
Function Numbers Quick Reference

Practical Examples

Basic SUM with Error Handling

Sum a range of sales values that contains #DIV/0! errors

Result: 1,330

Average of Visible Rows Only

Calculate average of filtered sales data in an Excel table

Result: 2,456.30

Maximum Value Ignoring Errors and Hidden Rows

Find the highest score while handling errors and filtered rows

Result: 98.5

Count Non-Empty Cells in Filtered Range

Count how many visible entries exist after filtering

Result: 347

Top 3 Values with LARGE Function

Find the 3rd largest sale amount ignoring errors

Result: 15,750

Dynamic Percentile Calculation

Calculate 90th percentile of response times, excluding errors and hidden rows

Result: 1,234

Product of Values Excluding Errors

Multiply growth rates together, handling errors gracefully

Result: 2.47

Common Errors and Solutions

#VALUE!

AGGREGATE function returns #VALUE! error

Cause:

Invalid function_num (not 1-19), invalid options value (not 0-7), or text in numeric range that cannot be ignored with current options

Solution:

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

Prevention:

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.

Frequency: 30%

Example:

#DIV/0!

Division by zero in AGGREGATE calculation

Cause:

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

Solution:

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

Prevention:

Before using AVERAGE-based functions, verify data exists: =IF(AGGREGATE(2,option,range)>0, AGGREGATE(1,option,range), "Insufficient data")

Frequency: 20%

Example:

#NUM!

Numeric error in AGGREGATE result

Cause:

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

Solution:

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

Prevention:

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))

Frequency: 15%

Example:

#REF!

Reference error in AGGREGATE

Cause:

Deleted cells, rows, or columns that ref1 or ref2 arguments reference. Also occurs when formula is copied to locations where references become invalid

Solution:

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

Prevention:

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.

Frequency: 10%

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.

AGGREGATE vs Alternative Functions
Real-World Applications
Conclusion and Next Steps

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: