How to use the AGGREGATE function
What is the AGGREGATE function?
The AGGREGATE function allows you to calculate different specific functions to a list or database. A special AGGREGATE function feature is to exclude hidden rows and error values in calculations.
Table of Contents
- Introduction
- Syntax
- Example 1 - AVERAGE
- Example 2 - COUNT
- Example 3 - COUNTA
- Example 4 - MAX
- Example 5 - MIN
- Example 6 - PRODUCT
- Example 7 - SUM
- What will the function not exclude?
- How to extract the largest number ignoring error values
- Function not working
- Get Excel *.xlsx file
Extract the largest number ignoring error values using arrays (Link)
1. Introduction
It is designed for columns of data or vertical ranges.
The formula above sums all values in cell range B3:B7 excluding errors.
Formula in cell D3:
2. Syntax
Reference form
AGGREGATE(function_num, options, ref1, [ref2], …)
Array form
AGGREGATE(function_num, options, array, [k])
The animated image above demonstrates how the AGGREGATE function guides you while selecting the first argument function_num.
function_num | Required. A number 1 to 19 that lets you choose between different functions. See the list below. |
Function | |
1 | AVERAGE |
2 | COUNT |
3 | COUNTA |
4 | MAX |
5 | MIN. |
6 | PRODUCT |
7 | STDEVS.S |
8 | STDEVS.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 |
The second argument is the options argument, the image above shows what choices you have.
Options | Required. A numerical value that allows you to choose which values to exclude in the calculation. |
0 or omitted. | Ignore nested SUBTOTAL and AGGREGATE functions |
1 | Ignore hidden rows, nested SUBTOTAL and AGGREGATE functions |
2 | Ignore error values, nested SUBTOTAL and AGGREGATE functions |
3 | Ignore hidden rows, error values, nested SUBTOTAL and AGGREGATE functions |
4 | Ignore nothing |
5 | Ignore hidden rows |
6 | Ignore error values |
7 | Ignore hidden rows and error values |
The AGGREGATE function has two different forms: array and reference. The array form allows you to use the following functions:
- LARGE(array,k)
- SMALL(array,k)
- PERCENTILE.INC(array,k)
- QUARTILE.INC(array,quart)
- PERCENTILE.EXC(array,k)
- QUARTILE.EXC(array,quart)
The reference form has these arguments:
AGGREGATE(function_num, options, ref1, [ref2], …)
Ref1 | Required. The first numeric argument for functions that take multiple numeric arguments for which you want the aggregate value. |
Ref2,... | Optional. Numeric arguments 2 to 253 for which you want the aggregate value. |
How do you choose the AGGREGATE form?
It depends on what function_num number you pick.
3. Example 1 - calculate the average
Calculate the arithmetic mean from these values [5, #DIV/0, 6, 4, #VALUE!]?
Here are the arguments:
Array form - AGGREGATE(function_num, options, array, [k])
- function_num - 1 (AVERAGE function)
- options - 6 (Ignore error values)
- array - B3:B7 (A cell reference to the values you want to calculate an average for.)
- [k] - optional (The AVERAGE function doesn't use the k argument, contrary to LARGE or SMALL functions.
The AVERAGE function calculates an average, however, it doesn't ignore error values or hidden rows. This is where the AGGREGATE function is really useful.
Formula in cell D3:
5 + 6 + 4 equals 15. 15/3 equals 5. This value matches the value in cell D3.
4. Example 2 - COUNT
Count the numerical values from this data set: [5, #DIV/0, 6, 4, #VALUE!]?
Here are the arguments:
Array form - AGGREGATE(function_num, options, array, [k])
- function_num - 2 (COUNT function)
- options - 6 (Ignore error values)
- array - B3:B7
- [k] - optional
Formula in cell D3:
Here is how the AGGREGATE evaluates the given arguments:
AGGREGATE(2, 6, B3:B7) becomes
AGGREGATE(2, 6, {5; #DIV/0!; 6; 4; #VALUE!}) and returns 3. There are three numbers in cell range B3:B7.
5. Example 3 - COUNTA
Count the non-empty values ignoring error values, from this data set: [5, #DIV/0, 6, 4, #VALUE!]?
Here are the arguments:
Array form - AGGREGATE(function_num, options, array, [k])
- function_num - 3 (COUNTA function)
- options - 6 (Ignore error values)
- array - B3:B7
- [k] - optional
Formula in cell D3:
Here is how the AGGREGATE evaluates the given arguments:
AGGREGATE(3, 6, B3:B7) becomes
AGGREGATE(3, 6, {5; #DIV/0!; ""; ""; #VALUE!}) and returns 1. There is only one non-empty value if you ignore the error values.
6. Example 4 - MAX
Calculate the maximum (largest) number ignoring error values, from this data set: [5, #DIV/0, 6, 4, #VALUE!]?
Here are the arguments:
Array form - AGGREGATE(function_num, options, array, [k])
- function_num - 4 (MAX function)
- options - 6 (Ignore error values)
- array - B3:B7
- [k] - optional
Formula in cell D3:
Here is how the AGGREGATE evaluates the given arguments:
AGGREGATE(3, 6, B3:B7) becomes
AGGREGATE(4, 6, {5; #DIV/0!; 6; 4; #VALUE!}) and returns 6. Six is the largest number in cell range B3:B7.
7. Example 5 - MIN
Calculate the minimum (smallest) number ignoring error values, from this data set: [5, #DIV/0, 6, 4, #VALUE!]?
Here are the arguments:
Array form - AGGREGATE(function_num, options, array, [k])
- function_num - 5 (MIN function)
- Array form - AGGREGATE(function_num, options, array, [k])
- options - 6 (Ignore error values)
- array - B3:B7
- [k] - optional
Formula in cell D3:
Here is how the AGGREGATE evaluates the given arguments:
AGGREGATE(5, 6, B3:B7) becomes
AGGREGATE(5, 6, {5; #DIV/0!; 6; 4; #VALUE!}) and returns 4. Four is the smallest number in cell range B3:B7.
8. Example 6 - PRODUCT
Calculate the PRODUCT (multiplication) ignoring error values, from this data set: [5, #DIV/0, 6, 4, #VALUE!]?
Here are the arguments:
Array form - AGGREGATE(function_num, options, array, [k])
- function_num - 6 (PRODUCT function)
- options - 6 (Ignore error values)
- array - B3:B7
- [k] - optional
Formula in cell D3:
Here is how the AGGREGATE evaluates the given arguments:
AGGREGATE(6, 6, B3:B7) becomes
AGGREGATE(6, 6, {5; #DIV/0!; 6; 4; #VALUE!}) and returns 120. 5 * 6 * 4 equals 120.
9. Example 7 - SUM
Calculate the sum (total) ignoring error values, from this data set: [5, #DIV/0, 6, 4, #VALUE!]?
Here are the arguments:
Array form - AGGREGATE(function_num, options, array, [k])
- function_num - 9 (SUM function)
- options - 6 (Ignore error values)
- array - B3:B7
- [k] - optional
Formula in cell D3:
Here is how the AGGREGATE evaluates the given arguments:
AGGREGATE(9, 6, B3:B7) becomes
AGGREGATE(9, 6, {5; #DIV/0!; 6; 4; #VALUE!}) and returns 15. 5 + 6 + 4 equals 15.
4. What will the AGGREGATE function not exclude?
The function will not exclude
- hidden rows
- nested subtotals
- nested aggregates if the array argument includes a calculation, for example:
When you type the first argument in the AGGREGATE function Excel returns a list of functions that are valid.
5. How to extract the largest number ignoring error values
The image above demonstrates how the AGGREGATE function is able to return the largest number and at the same time ignore error values.
Formula in cell D3:
This works fine as long as you are using cell references, however, it won't work if you try to use other functions in the third argument or use array values.
12. Function not working
The DAY function returns
- #VALUE! error if you use a non-numeric input value.
- #NAME? error if you misspell the function name.
- propagates errors, meaning that if the input contains an error (e.g., #VALUE!, #REF!), the function will return the same error.
12.1 Troubleshooting the error value
When you encounter an error value in a cell a warning symbol appears, displayed in the image above. Press with mouse on it to see a pop-up menu that lets you get more information about the error.
- The first line describes the error if you press with left mouse button on it.
- The second line opens a pane that explains the error in greater detail.
- The third line takes you to the "Evaluate Formula" tool, a dialog box appears allowing you to examine the formula in greater detail.
- This line lets you ignore the error value meaning the warning icon disappears, however, the error is still in the cell.
- The fifth line lets you edit the formula in the Formula bar.
- The sixth line opens the Excel settings so you can adjust the Error Checking Options.
Here are a few of the most common Excel errors you may encounter.
#NULL error - This error occurs most often if you by mistake use a space character in a formula where it shouldn't be. Excel interprets a space character as an intersection operator. If the ranges don't intersect an #NULL error is returned. The #NULL! error occurs when a formula attempts to calculate the intersection of two ranges that do not actually intersect. This can happen when the wrong range operator is used in the formula, or when the intersection operator (represented by a space character) is used between two ranges that do not overlap. To fix this error double check that the ranges referenced in the formula that use the intersection operator actually have cells in common.
#SPILL error - The #SPILL! error occurs only in version Excel 365 and is caused by a dynamic array being to large, meaning there are cells below and/or to the right that are not empty. This prevents the dynamic array formula expanding into new empty cells.
#DIV/0 error - This error happens if you try to divide a number by 0 (zero) or a value that equates to zero which is not possible mathematically.
#VALUE error - The #VALUE error occurs when a formula has a value that is of the wrong data type. Such as text where a number is expected or when dates are evaluated as text.
#REF error - The #REF error happens when a cell reference is invalid. This can happen if a cell is deleted that is referenced by a formula.
#NAME error - The #NAME error happens if you misspelled a function or a named range.
#NUM error - The #NUM error shows up when you try to use invalid numeric values in formulas, like square root of a negative number.
#N/A error - The #N/A error happens when a value is not available for a formula or found in a given cell range, for example in the VLOOKUP or MATCH functions.
#GETTING_DATA error - The #GETTING_DATA error shows while external sources are loading, this can indicate a delay in fetching the data or that the external source is unavailable right now.
12.2 The formula returns an unexpected value
To understand why a formula returns an unexpected value we need to examine the calculations steps in detail. Luckily, Excel has a tool that is really handy in these situations. Here is how to troubleshoot a formula:
- Select the cell containing the formula you want to examine in detail.
- Go to tab “Formulas” on the ribbon.
- Press with left mouse button on "Evaluate Formula" button. A dialog box appears.
The formula appears in a white field inside the dialog box. Underlined expressions are calculations being processed in the next step. The italicized expression is the most recent result. The buttons at the bottom of the dialog box allows you to evaluate the formula in smaller calculations which you control. - Press with left mouse button on the "Evaluate" button located at the bottom of the dialog box to process the underlined expression.
- Repeat pressing the "Evaluate" button until you have seen all calculations step by step. This allows you to examine the formula in greater detail and hopefully find the culprit.
- Press "Close" button to dismiss the dialog box.
There is also another way to debug formulas using the function key F9. F9 is especially useful if you have a feeling that a specific part of the formula is the issue, this makes it faster than the "Evaluate Formula" tool since you don't need to go through all calculations to find the issue..
- Enter Edit mode: Double-press with left mouse button on the cell or press F2 to enter Edit mode for the formula.
- Select part of the formula: Highlight the specific part of the formula you want to evaluate. You can select and evaluate any part of the formula that could work as a standalone formula.
- Press F9: This will calculate and display the result of just that selected portion.
- Evaluate step-by-step: You can select and evaluate different parts of the formula to see intermediate results.
- Check for errors: This allows you to pinpoint which part of a complex formula may be causing an error.
The image above shows cell reference B3:B7 converted to hard-coded value using the F9 key. The AGGREGATE function requires non-error values which is not the case in this example. We have found what is wrong with the formula. Note, the function has a setting that handles error values. Specify the second argument accordingly.
Tips!
- View actual values: Selecting a cell reference and pressing F9 will show the actual values in those cells.
- Exit safely: Press Esc to exit Edit mode without changing the formula. Don't press Enter, as that would replace the formula part with the calculated value.
- Full recalculation: Pressing F9 outside of Edit mode will recalculate all formulas in the workbook.
Remember to be careful not to accidentally overwrite parts of your formula when using F9. Always exit with Esc rather than Enter to preserve the original formula. However, if you make a mistake overwriting the formula it is not the end of the world. You can “undo” the action by pressing keyboard shortcut keys CTRL + z or pressing the “Undo” button
12.3 Other errors
Floating-point arithmetic may give inaccurate results in Excel - Article
Floating-point errors are usually very small, often beyond the 15th decimal place, and in most cases don't affect calculations significantly.
Useful links
AGGREGATE function - Microsoft
How to use the AGGREGATE Function (WS)
'AGGREGATE' function examples
Table of Contents Count cells containing text from list Count entries based on date and time Count cells with text […]
This article demonstrates ways to list unique distinct values in a cell range with multiple columns. The data is not […]
Functions in 'Math and trigonometry' category
The AGGREGATE function function is one of 62 functions in the 'Math and trigonometry' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form