Before we look at some examples of the AGGREGATE function in use, let’s see how it works. The AGGREGATE function has two syntaxes—one for references and one for arrays—though you don’t need to get yourself tied up in knots over which one you’re using, as Excel selects the relevant one depending on the arguments you input. You can see both syntaxes in use when I show you some examples soon.
The Reference Form Syntax
The syntax for the reference form of the AGGREGATE function is:
=AGGREGATE(a,b,c,d)
where
- a (required) is a number that represents the function you want to use in the calculation,
- b (required) is a number that defines what you want the calculation to ignore,
- c (required) is the range of cells on which the function will be applied, and
- d (optional) is the first of up to 252 additional arguments that specify further ranges.
The Array Form Syntax
On the other hand, if you’re working with arrays, the syntax is:
=AGGREGATE(a,b,c,d)
where
- a (required) is a number that represents the function you want to use in the calculation,
- b (required) is a number that defines what you want the calculation to ignore,
- c (required) is the array of values on which the function will be applied, and
- d is the second argument required by array functions like LARGE, SMALL, PERCENTILE.INC, and others.
Functions and Exclusions (Arguments a and b)
When entering arguments a and b in either syntax form above, you’ll have various options to choose from.
This table lists the numbers you can input to exclude certain values when creating your AGGREGATE formula (argument b):
Number | What Is Ignored |
---|---|
0 | Nested SUBTOTAL and AGGREGATE functions |
1 | Hidden rows, and nested SUBTOTAL and AGGREGATE functions |
2 | Errors, and nested SUBTOTAL and AGGREGATE functions |
3 | Hidden rows, error values, and nested SUBTOTAL and AGGREGATE functions |
4 | Nothing |
5 | Hidden rows only |
6 | Errors only |
7 | Hidden rows and errors |
Now, let’s look at some examples of how you can use the AGGREGATE function in real-world scenarios.
Example 1: Using AGGREGATE to ignore errors
This Excel spreadsheet contains a list of soccer players, the number of games they’ve played, the number of goals they’ve scored, and their game-per-goal ratios. Your aim is to work out the average game-per-goal ratio for all the players combined.
If you were to use the AVERAGE function alone by typing:
=AVERAGE(Player_Goals[Games per goal])
Instead, using the AGGREGATE function gives you the option to ignore these errors and return the average for the remaining data. To do this, in cell C2, you need to type:
=AGGREGATE(1,6,Player_Goals[Games per goal])
where
- 1 (argument a) represents the AVERAGE function,
- 6 (argument b) tells Excel to ignore errors, and
- Player_Goals[Games per goal] is the reference.
An alternative way to achieve the same outcome would be to use the IFERROR function in column D to replace any errors with a blank value.
Using the same spreadsheet, your next target is to calculate the total number of goals the team has scored.
Specifically, you want to display two totals. The first is the overall total when you combine the goals scored by all players, but the second is the total of only the players showing in the table after you apply filters.
To calculate the overall total, in cell C1, type:
=SUM(Player_Goals[Goals scored])
Now, even after you apply a filter to one of the columns, such as displaying only the players who have played 15 games or more, the SUM formula you just applied still includes the rows that are filtered out.
In cell C2, type:
=AGGREGATE(9,5,Player_Goals[Goals scored])
where
- 9 (argument a) represents the SUM function,
- 5 (argument b) tells Excel to ignore hidden rows, and
- Player_Goals[Goals scored] is the reference.
Now, notice that the result of this formula differs from the result of the SUM formula you used in cell C1, because it considers only the rows on display.
Example 3: Using AGGREGATE to Ignore Hidden Rows (Array)
Next, let’s say you wanted to list the two highest goal tallies for players who have played 20 games or fewer.
You could apply the filter first and then generate your formula, but for the purposes of this demonstration, let’s create the formula first.
In cell C1, type:
=AGGREGATE(14,5,Player_Goals[Goals scored],{1;2})
where
- 14 (argument a) represents the LARGE function,
- 5 (argument b) tells Excel to ignore hidden rows,
- Player_Goals[Goals scored] is the array of values, and
- {1;2} tells Excel that you want it to return the largest (1) and second-largest values (2) on separate rows (;).
When you press Enter, notice that the result is a spilled array covering cells C1 and C2 because you told Excel to return the top two values.
Now, filter the Games Played column to include only those players who have played 20 games or fewer, and see that the result of the AGGREGATE formula you entered earlier changes to ignore the hidden rows.
[mai mult...]