How to use the AVERAGEIFS function
What is the AVERAGEIFS function?
The AVERAGEIFS function returns the average of cell values that evaluates to TRUE for multiple criteria.
Table of Contents
1. Introduction
What is an average?
An average is a statistical measure of the central or typical value in a data set that provides an estimation of expected results by calculating the sum of values divided by total occurrences. Common averages include the arithmetic mean, median, and mode, each of which summarize data in different ways.
The AVERAGEIFS function calculates an arithmetic mean. For example, here is a group containing 4 numbers: 4, 2, 5, 3 The average is calculated like this: 4+2+5+3 = 14
14/4 = 3.5
3.5 is the arithmetic mean of 4, 2, 5, 3
What is IFS in the AVERAGEIFS function?
This means that the function allows you to specify a condition or critera in order to filter the values you want to calculate an average of.
2. Syntax
AVERAGEIFS(average_range, criteria_range1, criteria1, [criteria_range2] , [criteria2], ...)
The AVERAGEIFS function allows you to have up to 127 criteria and criteria_range arguments.
3. Arguments
average_range | Required. One or more cells to average, including numbers or names, arrays, or references that contain numbers. |
criteria_range1 | Required. A cell range in which to evaluate the corresponding condition |
criteria1 | Required. A condition in the form of a cell reference, expression or text that determines which values to be averaged. |
[criteria_range2] | Optional. You are allowed to have multiple criteria ranges. |
[criteria2] | Optional. You are allowed to have multiple criteria. |
4. What values are excluded?
Boolean values TRUE or FALSE are excluded in the calculation. All empty blank cell in argument average_range are also excluded.
5. Function not working
Here are some recommendations you may want to check if your AVERAGEIFS function is not working.
- A blank or text value in the argument range is not valid, the function returns #DIV0!.
- A value is used in the calculation only if all of the corresponding criteria specified are true for that cell.
- If a condition in argument average_range is empty is the same as 0 (zero).
- The AVERAGEIFS function returns #DIV0! if no values match the criteria.
5.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.
5.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 D3:D8 converted to hard-coded value using the F9 key. The AVERAGEIFS function requires valid non-error values which is not the case in this example. We have found what is wrong with the formula.
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
5.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.
6. Example
This example demonstrates how to use the AVERAGEIFS function with three conditions. The image above shows a data table in cell range B3:E8, it has 4 columns with these column header names: Item, Level, Color, and Price.
The conditions are specified below the data table in cell range B11:D11. The formula in cell E11 uses comparison operators to create advanced conditions. They allow you to specify conditions that are smaller, larger or not equal to the conditions specified in cell B11:D11.
Formula in cell E11:
The formula in cell E11 in the picture above calculates the average for values in cell range E3:E8 that match all the conditions on the same row. It checks i cells in B3:B8 match the value in B11 meaning the entire cell value must be equal to the entire cell value in cell B11. You don't need to specify the equal sign to compare values, the formula compares values in its default state.
The next condition checks if the numbers in cell range C3:C8 are smaller than the value in C11. The ampersand character lets you append a comparison character to the cell reference. <"&C11 You can also enter the comparison operators in the cells B11:D11 if you want and skip the ampersand all together.
The third and last condition is specified in cell D11. This condition uses the less than and greater than signs combined meaning "not equal to". This means that all values that doesn't match the value in cell D11 is a match. Confusing?
When we apply all the criteria to the data table we get the following values:
- 3 from cell E4. B4 matches B11, C4 is smaller than C11, D4 is not equal to D11.
- 2 from cell E7. B7 matches B11, C7 is smaller than C11, D7 is not equal to D11.
We can now calulate the average: 3+2 equals 5. 5 / 2 equals 2.5 which is the same value in cell E11.
Explaining formula
The AVERAGEIFS function lets you use comparison operators, they are:
- < less than character
- > larger than character
- <= less than or equal to
- >= larger than or equal to
- <> not equal to
Step 1 - AVERAGEIFS function
AVERAGEIFS(average_range, criteria_range1, criteria1, [criteria_range2] , [criteria2], ...)
Step 2 - Populate arguments
average_range - E3:E8
criteria_range1 - B3:B8
criteria1 - B11
criteria_range2 - C3:C8
criteria2 - "<"&C11
criteria_range3 - D3:D8
criteria3 - "<>"&D11
Step 3 - Evaluate function
AVERAGEIFS(D3:D8, B3:B8, F3, C3:C8, G3)
becomes
AVERAGEIFS({5; 3; 6; 3; 2; 4}, {"A"; "B"; "A"; "B"; "B"; "A"}, "B", {1; 2; 3; 1; 2; 3}, "<"&3, {"Black"; "White"; "Black"; "Black"; "White"; "White"}, "<>"&"Black")
and returns 2.5
First condition matches cells B4,B6, and B7.
The second condition matches C3, C4, C6, and C7.
The third condition matches D4, D7, and D8.
Rows that match all conditions are 4 and 7, cells E4 and E7 contain 3 and 2. 3 + 2 equals 5. 5/2 is 2.5
7. Example 2 - wildcard characters
The comparison operators described above are not the only characters you can use. It is also possible to use wildcard characters like (?) question mark or (*) asterisk.
- (?) question mark matches any single character.
- (*) asterisk matches any sequence of characters.
- Use a tilde (~) before to escape the wildcard characters meaning finding the actual question mark or asterisk.
The following examples below demonstrate how to use these characters.
7.1 Begins with
The image above demonstrates a formula in cell C11 that average numbers if values on the same row begin with a specific condition.
The data table is in cell B3:C7 and has the following header names: Value and Numbers. The condition is specified in cell B11 and the formula below uses a asterisk character to match any character.
This means that the formula matches values in B3:B7 that begins with the string specified in cell B11. Note that this operation is not case- sensitive meaning it matches the string without considering upper and lower characters.
Formula in cell F3:
The formula in cell C11 matches the following cell values:
- B3 - "LV-104". This value begins with the same string specified in cell B11. The corresponding value in column C is 8.
- B11 - "LV-305". This value begins with the same string specified in cell B11. The corresponding value in column C is 3.
We can now calculate the average based of these two numbers. 8 + 3 = 11. 11 / 2 equals 5.5 which is the value in cell C11.
Explaining formula
Step 1 - Populate arguments
AVERAGEIFS(average_range, criteria_range1, criteria1, [criteria_range2] , [criteria2], ...)
average_range - B3:B7
criteria - E3&"*"
criteria_range - C3:C7
Step 2 - Evaluate AVERAGEIF function
AVERAGEIFS(C3:C7, B3:B7, B11&"*")
becomes
AVERAGEIFS({8; 3; 5; 3; 2}, {"LV-104"; "BV-10"; "BC-201"; "LV-305"; "BV-209"}, "LV*")
and returns 5.5
Cells B3 and B6 begin with the given value in cell B11, the corresponding values are in C3 and C6. They contain 8 and 3, 8 + 3 equals 11. 11/2 equals 5.5
7.2 Ends with
The image above shows a data table in cell B3:C7 with the following column names: Value and Numbers. The condition is specified in cell B11.
The formula in cell C11 calculates an average based on numbers in C3:C7 if the corresponding value in cell range B3:B7 does NOT end with the value specified in cell B, in this example, 1.
Formula in cell C11:
In other words, the formula matches values in cell range B3:B7 that don't end with number 1. "<>*"&B11 contains less than and greater than signs combined meaning not equal to and the asterisk. The asterisk match any character and any number of characters.
Cells B3, B4, B6, and B7 contain values that don't end with 1, the corresponding numbers on the same rows are 8, 3, 3, and 2. 8 + 3 + 3 + 2 equals 16. 16/4 equals 4
Explaining formula
Tip! You can use the "Evaluate" tool found on tab "Formulas" on the ribbon to examine the formula step by step. This makes it easier to troubleshoot and understand more complicated formulas.
Step 1 - Populate arguments
AVERAGEIFS(average_range, criteria_range1, criteria1, [criteria_range2] , [criteria2], ...)
average_range - B3:B7
criteria - "<>*"&B11
criteria_range - C3:C7
Step 2 - Evaluate AVERAGEIF function
AVERAGEIFS(C3:C7, B3:B7, "<>*"&B11)
becomes
AVERAGEIFS({8; 3; 5; 3; 2}, {"LV-104"; "BV-10"; "BC-201"; "LV-305"; "BV-209"}, "<>*1")
and returns 4.
7.3 Contains a string
This example shows data table in cell B3:C7, the column header names are: Value and Number.
The AVERAGIFS function in cell C11 calculates an average based on numbers in cell range C3:C7, if the corresponding value on the same row in cell range B3:B7 contains the condition specified in cell B11.
In other words, this is different than the other examples above meaning a match is found if a substring specified in cell B11 is found in a cell value in cell range B3:B7. This is not a case sensitive search meaning upper and lower characters are not considered different.
Formula in cell C11:
The formula above appends asterisks to both the beginning and the end of the condition. The condition in cell B11 matches cells B3, B4, B6, and B7. The corresponding values in column C are: 8, 3, 3, and 2.
The average is calculated like this: 8+3+3+2 equals 16. 16 / 4 equals 4. The average is 4 and cell C11 shows the same value.
Explaining formula
Step 1 - Populate arguments
AVERAGEIFS(average_range, criteria_range1, criteria1, [criteria_range2] , [criteria2], ...)
average_range - C3:C7
criteria_range1 - B3:B7
criteria - "*"&B11&"*"
Step 2 - Evaluate AVERAGEIF function
AVERAGEIFS(C3:C7, B3:B7, "<>*"&B11)
becomes
AVERAGEIFS({8; 3; 5; 3; 2}, {"LV-104"; "BV-10"; "BC-201"; "LV-305"; "BV-209"}, "*V*")
and returns 4.
8. Caveats
The AVERAGEIFS function will not accept arrays or nested functions in any of the arguments which makes the AVERAGEIFS function not that useful for more advanced calculations in my opinion.
The image above demonstrates the AVERAGEIFS function nested with the TEXTSPLIT and INDEX function, unfortunately, it doesn't work.
What if we use "helper"-cells to perform intermediate calculations? Cell B5 contains: TEXTSPLIT(B3, ",", ";"). It is a dynamic array formula that spills values to cells below and to the right based on delimiting characters.
No, the AVERAGEIFS function returns a #DIV/0! error. The AVERAGEIFS function seems to be incompatible with new dynamic array functions in Excel 365.
Referencing dynamic arrays won't work either:
This returns a #DIV/0! error as well.
Functions in 'Statistical' category
The AVERAGEIFS function function is one of 73 functions in the 'Statistical' 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