How to use the MAXIFS function
What is the MAXIFS function?
The MAXIFS function returns the largest number based on a condition or criteria.
The MAXIFS function was introduced in Excel 2016. Use the MAX function and logical expressions if you have an earlier Excel version.
Table of Contents
1. Syntax
MAXIFS(max_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)
You can enter up to 126 range/criteria pairs.
2. Arguments
max_range | Required. A cell reference to numbers which the highest value will be calculated. |
criteria_range1 | Required. The cell range you want to apply a specific condition to. |
criteria1 | Required. The condition you want to use. |
[criteria_range2] | Optional. Additional cell ranges. |
[criteria2] | Optional. Additional criteria. |
3. Example
The formula in cell F3 extracts the largest number in C3:C9 if the corresponding value on the same row in B3:B9 equals the condition specified in cell F2. Here is the data in the data table shown in cell range B2:C9 in the image above:
Region | Amount |
Asia | 100 |
Africa | 10 |
Africa | 2 |
Africa | 4 |
Asia | 50 |
Asia | 65 |
Asia | 47 |
The specified condition in cell F2 is "Africa". Cells B4, B5, and B6 math "Africa, the corresponding values in cell range C3:C9 are 10, 2, and 4.
Formula in cell F3:
The largest value of 10, 2, and 4 is 10 which is what the formula in cell F3 returns.
3.1 Explaining formula
The Evaluate Formula tool is located on the Formulas tab in the Ribbon. It is a useful feature that allows you to step through and evaluate complex formulas to understand how the calculation is being performed and identify any errors or issues. The following steps shows these detailed evaluations for the formula above.
Step 1 - Populate arguments
MAXIFS(max_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)
max_range - C3:C9
criteria_range1 - B3:B9
criteria1 - F2
Step 2 - Evaluate function
MAXIFS(B3:B9, B3:B9, F2)
becomes
MAXIFS({100; 10; 2; 4; 50; 65; 47}, {"Asia"; "Africa"; "Africa"; "Africa"; "Asia"; "Asia"; "Asia"}, "Africa")
and returns 10 in cell F3. 10 is the largest number of 10, 2, and 4.
4. Working with criteria
This example demonstrates the MAXIFS function using multiple conditions to extract the correct number. The data table displayed in cell range B2:D9 has the following values:
Region | Category | Amount |
Asia | B | 100 |
Africa | B | 10 |
Africa | A | 2 |
Africa | A | 4 |
Asia | B | 50 |
Asia | B | 65 |
Asia | A | 47 |
The formula in cell G4 in the picture above extracts the largest number (amount) that corresponds to the first condition which is region "Asia" and the second condition which is category "B". The first condition is specified in cell G2, the second condition is specified in cell G3.
Formula in cell G4:
Both conditions are met on rows 3, 7, and 8. The corresponding values are 100, 50, and 65 from column D. The largest (max) of the three values is 100.
4.1 Explaining formula
The Evaluate Formula tool is located on the Formulas tab in the Ribbon. It is a useful feature that allows you to step through and evaluate complex formulas to understand how the calculation is being performed and identify any errors or issues. The following steps shows these detailed evaluations for the formula above.
Step 1 - Populate arguments
MAXIFS(max_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)
max_range - B3:B9
criteria_range1 - B3:B9
criteria1 - E2
[criteria_range2] -
[criteria2]
Step 2 - Evaluate function
MAXIFS(B3:B9, B3:B9, E2)
becomes
MAXIFS({100; 10; 2; 4; 50; 65; 47}, {100; 10; 2; 4; 50; 65; 47}, "<55")
and returns 50 in cell E3.
5. Conditional operators - smaller than
The formula in cell E3 extracts the largest number in B3:B9 smaller than 55, condition "55" is specified in cell E2. The data table is:
Number |
100 |
10 |
2 |
4 |
50 |
65 |
47 |
The following numbers match the condition smaller than 55: 2, 4, 47, and 50.
Formula in cell E3:
The largest value of 2, 4, 47, and 50 is 50 which is the same number the formula returns in cell E3. This example shows that you can also apply a condition to the numbers themself.
5.1 Explaining formula
The Evaluate Formula tool is located on the Formulas tab in the Ribbon. It is a useful feature that allows you to step through and evaluate complex formulas to understand how the calculation is being performed and identify any errors or issues. The following steps shows these detailed evaluations for the formula above.
Step 1 - Populate arguments
MAXIFS(max_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)
max_range - B3:B9
criteria_range1 - B3:B9
criteria1 - E2
Step 2 - Evaluate function
MAXIFS(B3:B9, B3:B9, E2)
becomes
MAXIFS({100; 10; 2; 4; 50; 65; 47}, {100; 10; 2; 4; 50; 65; 47}, "<55")
and returns 50 in cell E3. 50 is the largest number of 10, 2, 4, 50, and 47.
6. Extract the largest number ignoring error values
The MAXIFS function ignores errors if you add a criteria pair that filters values above or equal to the smallest number in your data set.
Surprisingly, this doesn't work if you use a condition like in section 3. You need to use a smaller than or larger than sign in order to ignore error values.
You can't use the IFERROR function combined with the MAXIFS function unfortunately, however, a workaround is to use the MAX function, IF function and the IFERROR function, like this: =MAX(IF(IFERROR(B3:B9,"")>=-15,IFERROR(B3:B9,""),"")) This formula must be entered as an array formula if you use an earlier Excel version than Excel 365.
Formula in cell E2:
Note that the formula in cell E2 works only with cell ranges and not arrays. The image below demonstrates this problem with array values.
7. Use arrays in MAXIFS function
In fact, the MAXIFS function doesn't accept anything else than cell references as max_range and criteria_range.
I recommend the IFERROR function and the regular MAX function to filter out error values.
Example array formula:
7.1 How to enter an array formula
The image above shows leading and trailing curly brackets. They appear automatically when you follow the steps below.
- Copy the array formula above.
- Double press with the left mouse button on cell D3, a prompt appears.
- Paste it to cell C3, shortcut keys are CTRL + v.
- Press and hold CTRL + SHIFT keys simultaneously.
- Press Enter once.
- Release all keys.
The formula bar shows a beginning and ending curly bracket, don't enter these characters yourself.
7.2 Explaining array formula
The Evaluate Formula tool is located on the Formulas tab in the Ribbon. It is a useful feature that allows you to step through and evaluate complex formulas to understand how the calculation is being performed and identify any errors or issues. The following steps shows these detailed evaluations for the formula above.
Step 1 - Replace error values with blanks
The IFERROR function can replace error values with a given value.
IFERROR(value, value_if_error)
IFERROR(B3:B9, "")
becomes
IFERROR({-15; #DIV/0!; 2; 4; #N/A; 65; 47}, "")
and returns
{-15; ""; 2; 4; ""; 65; 47}
Step 2 - Get the largest number
The MAX function returns the largest number ignoring text and blank values.
MAX(IFERROR(B3:B9, ""))
becomes
MAX({-15; ""; 2; 4; ""; 65; 47})
and returns 65.
8. Use other functions
No, you can't use other functions combined with the MAXIFS function at all. The picture above shows a nested MAXIFS function. It contains an IF function in the first argument and it returns a bunch of error values in Excel 365.
This makes the MAXIFS function quite limited unfortunately.
9. Perform calculations
No, the image above shows a dialog box containing a warning message. It appears when I tried to add 1 to the cell reference in the first argument.
The warning dialog box contains the following message:
There's a problem with this formula.
Not trying to type a formula?
When the first character is an equal (=) or minus (-) sign, Excel thinks it's a formula:
you type: =-1, cell shows: 2
To get around this, type an apostrophe (') first:
you type: '=-1, cell shows: =-1
The formula I am trying to use is:
This formula shows that you can't perform calculations inside the MAXIFS function at all, the function is very limited unfortunately.
10. Function not working
The MAXIFS function returns
- #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.
10.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.
10.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 C3:C9 converted to hard-coded value using the F9 key. The MAXIFS function requires non-error values in the first argument 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
10.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.
'MAXIFS' function examples
Table of Contents Find and return the highest number and corresponding date based on a condition Lookup value based on […]
This article demonstrates how to return the latest date based on a condition using formulas or a Pivot Table. The […]
Functions in 'Statistical' category
The MAXIFS 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