Back to Blog

The AGGREGATE Function in Excel

Excel is a great tool for storing and managing your data. However, looking through each entry can be overwhelming when it comes to understanding what all that data is telling us. You often want to aggregate or summarize your data to better understand any trends, rankings, or other insights hidden in the data.

Have you heard of Excel’s AGGREGATE function? Well, it’s a powerful tool that allows you to calculate sums, averages, counts, and many other types of data aggregations. It can even ignore error values ​​and hidden rows if needed.

This article will go over the syntax and usage of AGGREGATE, as well as some examples. So, read on to learn about this amazing function! 😉

How to aggregate data in Excel

You can aggregate data in Excel using several different methods:

#1: Using aggregate functions 

Aggregate functions calculate a set of values and return a single value as a summary result. The five most common functions are SUM, AVERAGE, COUNT, MAX, and MIN—which you may already be familiar with. There’s even an AutoSum button in the Home tab for these functions so that you don’t have to manually type them. 

Figure 1.1.1. The most common aggregate functions in the AutoSum button

There are also functions such as SUMIF/SUMIFS, COUNTIF/COUNTIFS, MAXIFS, MINIFS, etc., to help you summarize data using specific criteria. Statistical functions such as MODE and MEDIAN are also available.

Additionally, Excel has special functions like AGGREGATE and SUBTOTAL that bring together many aggregate functions into one convenient package. 

The AGGREGATE function is the focus of this article. And if you haven’t heard of or used the AGGREGATE function before, don’t worry; we cover that later in this article.

#2: Other options: Pivot tables and Power Query

Both are great for summarizing and analyzing your data. 

You may want to use Power Query’s data transformation tools to apply groupings or use aggregate functions to summarize your data. Or, you may want to use a pivot table to create a nice table visualization containing aggregated values ​​as shown below:

Figure 1.2.1. Aggregate data in Excel using a pivot table

Before summarizing your data using one of these tools, it’s not uncommon that you need to get raw data from an external source and do some cleanups. With Excel Power Query, you can easily create connections from many external sources, and also use them when creating pivot tables. 

Now, what if you need to import data from many different sources, but are not familiar using Power Query? 

An alternative is using an integration tool such as Coupler.io that allows you to import data from various sources into Excel without coding! With this tool, you can easily get data from apps such as Jira, QuickBooks, Shopify, Hubspot, and more! 

Figure 1.3. Coupler.io as a solution to import data to Excel from different sources

Don’t forget to check out Microsoft Excel integrations supported by Coupler.io.

Now, what is the AGGREGATE function in Excel?

When you’re summarizing data using aggregate functions, a single cell’s error could cause the formulas not to work. There are situations when you just don’t have time to fix errors in your data. Especially, when you’re processing a large amount of data.

Fortunately, there is this function called AGGREGATE that was introduced in Excel 2010. You can use it as a multipurpose function to do different data aggregations like finding sums, averages, etc. while ignoring errors and hidden rows. 

AGGREGATE formula in Excel: Syntax and parameters

The Excel AGGREGATE function can have two syntax forms: reference and array syntaxes. 

Syntax

Reference form:

=AGGREGATE(function_num, options, ref1, [ref2], ...)

Array form:

=AGGREGATE(function_num, options, array, [k])

You do not need to worry about which form you are using. Excel will select the appropriate form based on the input parameters you specify. 

Parameters or arguments

The following are the parameters used in the AGGREGATE function.

ParameterExplanation
function_numRequired. A number 1 to 19 that specifies which aggregate function is to be performed. 
optionsRequired. A number 0 to 7 that determines what to ignore in the evaluation range for the function.
ref1, [ref2], … ref1: Required. A reference to the range of cells on which the function is to be applied.
[ref2], …: Optional. Additional range of cells. There can be up to 253 separate ranges (including ref1), each separated by a comma.
array, [k]array: An array of values or an array formula upon which the function is to be applied.
[k]: A second argument that is required by certain functions when using an array of values or an array formula.
See the following functions that require the [k] argument:
  • LARGE(array, k)k is the nth largest value to be found.
  • SMALL(array, k)k is the nth smallest value to be found.
  • PERCENTILE.INC(array, k)k is the percentage value, must be between 0 and 1.
  • QUARTILE.INC(array, quart) — quart is the quartile, must be 0, 1, 2, 3, 4.
  • PERCENTILE.EXC(array, k)k is the percentage value, must be between 0 and 1. 
  • QUARTILE.EXC(array, quart) — quart is the quartile, must be 0, 1, 2, 3, 4.
  • There are 19 different aggregate functions you can use with AGGREGATE. While it doesn’t cover all of the aggregate functions in Excel, it does offer a wide range of choices. You also have 8 choices to specify how hidden cells and errors are handled using this function.

    The 19 functions supported by AGGREGATE

    The table below lists the aggregate functions you can use with AGGREGATE. The values 1-19 in the first column are used as the first argument of this function.

    function_numAggregate function
    1AVERAGE
    2COUNT
    3COUNTA
    4MAX
    5MIN
    6PRODUCT
    7STDEV.S
    8STDEV.P
    9SUM
    10VAR.S
    11VAR.P
    12MEDIAN
    13MODE.SNGL
    14LARGE
    15SMALL
    16PERCENTILE.INC
    17QUARTILE.INC
    18PERCENTILE.EXC
    19QUARTILE.EXC

    The 8 options to handle errors and/or hidden rows

    Here are options to specify how errors and hidden rows are handled using AGGREGATE. The values 0-7 in the first column of the table below are used as the second argument of this function.

    optionsWhat to ignore
    0 or [blank]Ignore nested SUBTOTAL and AGGREGATE functions
    1Ignore hidden rows, nested SUBTOTAL, and AGGREGATE functions
    2Ignore error values, nested SUBTOTAL, and AGGREGATE functions
    3Ignore hidden rows, error values, nested SUBTOTAL, and AGGREGATE functions
    4Ignore nothing
    5Ignore hidden rows
    6Ignore error values
    7Ignore hidden rows and error values

    Please note, the AGGREGATE function is designed to work only with vertical ranges, so there is no option to ignore hidden columns.

    You may be wondering what SUBTOTAL is. Well, it’s a function that works similarly to AGGREGATE. However, SUBTOTAL supports only 11 aggregate functions, and there is no option to ignore errors.

    How to use AGGREGATE function in Excel: Basic usage

    Let’s take a look at how to use this function with a basic example.

    Suppose you have the following data and want to find the average bonus given to salespeople. As you can see, there are cells with #N/A errors in the range C2:C9. If you use the AVERAGE function on this range, you will also get an #N/A result — see the following screenshot:

    Figure 4.1. AGGREGATE function Excel Basic usage example

    Now, let’s use AGGREGATE in F3 to find the average by following the steps below:

    Step 1: Type =AGGREGATE(. You will see a list of aggregate functions appear in a dropdown. 

    Figure 4.2. Typing AGGREGATE in Excel

    Step 2: Manually type the function number (function_num) you want to use, or just double-click it. In this case, enter 1, which is the number for the AVERAGE function. 

    Figure 4.3. Specifying the function num value

    Step 3: Type a comma, and in the options list that appears, select 6 to ignore errors.

    Figure 4.4. Specifying what to ignore

    Step 4: Type a comma again. After that, enter the range you want to calculate and close the bracket.

    Figure 4.5. Specifying the range to calculate

    Step 5: Press Enter

    Figure 4.6. AGGREGATE function Excel Final result

    Here’s the AGGREGATE Excel formula we use in F3:

    =AGGREGATE(9,6,D2:D11)

    The function returns an average result (function_num = 1) of the values in the range C2:C9. It allows us to ignore any errors in the range and returns a result. As you can see, the result of this function is not an #N/A error like the result of the AVERAGE function in F2.

    Excel AGGREGATE function: More examples

    Let’s see more examples of how to use AGGREGATE in different scenarios.

    Example  #1: Data aggregation in Excel by ignoring hidden rows

    With the following data, suppose you want to know how many products are in January 2022 promotions. To do that, you calculate the number of cells in B2:B11 that are not blank using the COUNTA function in E4. 

    Figure 5.1.1. Using the COUNTA function to calculate the number of non empty cells

    With Rosa Glauca set to be discontinued in January 2022, you might want to hide Row 10 manually. However, when printing the data with summary info, this could cause confusion. That’s because the COUNTA’s result will be the same even after the row is hidden. 

    One way around this problem is using AGGREGATE with COUNTA function to ignore hidden rows, as follows:

    =AGGREGATE(5,3,D2:D11)
    Figure 5.1.2. Using AGGREGATE with COUNTA to ignore hidden rows

    Example #2: Aggregation Excel – multiple references

    In the following example, we calculate the maximum amount of sales in January – June, which are in ranges B2:D11 and F2:H11. Notice that the MAX function in L4 returns an error, while AGGREGATE doesn’t.

    Here’s the AGGREGATE formula we use in L5 that uses MAX (function_num = 4) while ignoring errors (options = 6). 

    =AGGREGATE(4,6,B2:D11,F2:H11)
    Figure 5.2.1. Using AGGREGATE with multiple references

    Example #3. Aggregation Excel – Ignore nested AGGREGATE

    For this example, we’ll use the same case and data as Example #2 above. We are going to calculate the maximum amount of sales in January – June. But now, we are using range B2:I11 instead of multiple references. 

    Let’s take a closer look at the calculations in columns Q1 and Q2 that use AGGREGATE with SUM by ignoring error values, as shown in the following screenshot:

    Figure 5.3.1. Ignore nested AGGREGATE example

    To find the maximum values in January – June, we can simply use this AGGREGATE formula that ignores errors and nested AGGREGATE (options = 2):

    =AGGREGATE(4,2,B2:I11)
    Figure 5.3.2. Ignore nested AGGREGATE result

    Example #4. Excel AGGREGATE function with [k] parameter

    Suppose you have the following product sales data and want to calculate the 1st, 2nd, and 3rd largest sales:

    Figure 5.4.1. Data aggregation MS Excel with k parameter example

    As shown in the above screenshot, here are the formulas in E4, E5, and E6:

    =AGGREGATE(14,6,B2:B11,1)
    =AGGREGATE(14,6,B2:B11,2)
    =AGGREGATE(14,6,B2:B11,3)

    The AGGREGATE formulas above use LARGE (function_num = 14) in range B2:B11 while ignoring errors (options = 6). 

    Notice that the [k] parameter is the nth largest value to be found in the range. Please note that if you don’t provide a value for this parameter, AGGREGATE returns a #VALUE! error.

    Example #5. Excel AGGREGATE function with [k] parameter and array formula

    Let’s see a more complex example that uses an array formula. 

    The following AGGREGATE formulas are used to calculate the 1st, 2nd, and 3rd smallest values of product sales for products in the “Sunflower” category.

    Figure 5.5.1. Excel AGGREGATE function with k parameter and array formula example

    The formulas in E4, E5, and E6 are:

    =AGGREGATE(15,6,C2:C11/(B2:B11="Sunflower"),1)
    =AGGREGATE(15,6,C2:C11/(B2:B11="Sunflower"),2)
    =AGGREGATE(15,6,C2:C11/(B2:B11="Sunflower"),3)

    Notice that the AGGREGATE formulas above use SMALL (function_num = 15) in range C2:C11 where values in B2:B11 equal “Sunflowers”. All errors are ignored (options = 6).

    Here’s how Excel evaluates the formula to find the smallest value:

    • The logical expression B2:B11="Sunflower" returns an array of TRUE/FALSE values: {TRUE;FALSE;FALSE;FALSE;FALSE;TRUE;TRUE;FALSE;FALSE;TRUE}.
    • The C2:C11/(B2:B11="Sunflower") evaluates to: {90000;85000;#N/A;55000;40000;22000;92000;55000;65000;35000} /({TRUE;FALSE;FALSE;FALSE;FALSE;TRUE;TRUE;FALSE;FALSE;TRUE})
    • FALSE evaluates as zero and throws a #DIV/0! error. TRUE evaluates as 1 and returns the original value. Thus, the previous expression becomes:
      {90000;#DIV/0!;#N/A;#DIV/0!;#DIV/0!;22000;92000;#DIV/0;#!DIV/0!;35000}.
    • The final formula: =AGGREGATE(15,6,{90000;#DIV/0!;#N/A;#DIV/0!;#DIV/0!;22000;92000;#DIV/0;#!DIV/0!;35000},1) returns 22000, which is the smallest value in the array.  

    Isn’t it interesting that you don’t need to press Ctrl+Shift+Enter when using AGGREGATE with an array formula? 🙂

    What is table aggregation in Excel?

    Well, it’s simply an aggregation applied to an Excel table. You’ll find it easier and more flexible than doing it on ranges of data. 

    So, when you have data in rows and columns in Excel, formatting it as a table will give you more benefits. For example, filtering or aggregating your data becomes easier and more time-saving. 

    If you don’t know how to format your data as a table, follow the steps below:

    Click on any cell of your data, then click the Insert tab on the ribbon and click Table. Then, in the “Create Table” dialog that appears, click OK if the data range and header option are correct.

    Figure 6.1. Formatting a data range as an Excel table

    After that, Excel creates a table for you.

    In the Table Design tab, you can see the default name of your table. You can rename it, as well as change other settings such as table formatting and style.

    Figure 6.2. The Table Design tab

    To apply aggregation to your table, you can easily tick the Total Row option in the Table Style Options group:

    Figure 6.3. Adding the total row to an Excel table

    You will see a summary row added at the bottom, and by default, it uses a SUBTOTAL function, which allows you to include or ignore hidden rows but not error values:

    Figure 6.4. The Total row

    However, you can change it to use other functions such as SUM, AVERAGE, AGGREGATE, etc., by using the dropdown in the Total row or writing your own.

    For example, here we use an AGGREGATE function to sum the Sales (function_num = 9) by ignoring errors and hidden rows (options = 7). We get the following result, which is not an #N/A error: 

    =AGGREGATE(9,7,[Sales])
    Figure 6.5. A table aggregation using AGGREGATE

    Now, if you filter the table, you’ll see that the total is automatically updated to ignore hidden rows:

    Figure 6.6. A filtered table

    Should you change an aggregation function in Excel to use AGGREGATE?

    You’ve seen how the AGGREGATE function in Excel can be so powerful because it supports 19 aggregate functions and can ignore errors, hidden rows, and nested AGGREGATE or SUBTOTAL. 

    That makes AGGREGATE perfect for replacing those 19 aggregate functions!

    So, should you use it all the time? 

    Well, if you want, of course you can! There are many good reasons to use AGGREGATE. This function can do 152 different things (19 functions x 8 options), handle array formulas for certain functions, and is very fast to use on a large dataset.

    However, please keep in mind that this function is only available in Excel 2010 or later versions. It’s also more complicated to use it than using SUM, COUNT, or other aggregate functions.

    So, in some cases, you may want to simply use aggregate functions instead of AGGREGATE. For example, when your dataset is not too large, and you have time to correct any errors in your data.

    Finally, thanks for reading—and happy summarizing!

    Back to Blog

    Comments are closed.

    Access your data
    in a simple format for free!

    Start Free