How to use the IFS function
The IFS function checks whether one or more conditions are met and returns a value that corresponds to the first TRUE condition.
The image above shows the IFS function in column C, it returns "Larger than 50" if the corresponding value on the same row in column B is larger than 50.
It also returns "Smaller than or equal to 50" if the corresponding value is smaller than or equal to 50.
Table of Contents
1. Syntax
IFS(logical_expression1, Value_if_True1, [logical_expression2, Value_if_True2],…)
The IFS function allows you to have up to 127 pairs of logical expressions and values if the logical expression evaluates to true.
2. Arguments
logical_expression1 | Required. The logical expression you want to use. |
Value_if_True1 | Required. The value to be displayed if the logical expression is met. |
[logical_expression2] | Optional. Additional logical expression. |
[Value_if_True2] | Optional. Additional value to be returned if the logical expression evaluates to true. |
3. Example 1
The IFS function is a better alternative to nested IF functions, the formula becomes a lot simpler and easier to understand.
This example shows how to calculate a grade based on a score.
Formula in cell C3:
The formula in the above picture calculates the grade based on the following score levels.
A+ score > 95
A score > 89.
B+ score > 84
B score > 79
C+ score > 74
C score > 69
D+ score > 64
D score > 59
F score > 60
4. Alternative
The IFS function is an Excel 2016 function, however, you can replicate the behavior with the following formula if you have an earlier version of Excel.
Formula in cell C3:
The formula above uses the table E3:F11 to match the score with the correct grade.
4.1 Explaining formula
Step 1 - Find a relative position in the table of a given value
The MATCH function returns the relative position of an item in an array or cell reference that matches a specified value in a specific order.
MATCH(lookup_value, lookup_array, [match_type])
MATCH(B3, $E$3:$E$11)
becomes
MATCH(63, {0; 60; 65; 70; 75; 80; 85; 90; 96})
The third argument determines what the requirements are, read more: MATCH function. I know there is no third argument in this example, however, the default value is 1 meaning: Finds the smallest value that is greater than or equal to lookup_value. Lookup_array must be sorted in a descending order
and returns 2.
Step 2 - Return the corresponding value
The INDEX function returns a value from a cell range, you specify which value based on a row and column number.
INDEX(array, [row_num], [column_num], [area_num])
INDEX($F$3:$F$11, MATCH(B3, $E$3:$E$11))
becomes
INDEX({"F"; "D"; "D+"; "C"; "C+"; "B"; "B+"; "A"; "A+"}, 2)
and returns "D" in cell C3.
5. Example 2 - convert month number to month name
Formula in cell C3:
Explaining formula in cell B3
Step 1 - Calculate month number based on a date
The MONTH function extracts the month as a number from an Excel date.
MONTH(serial_number)
MONTH(B3)
becomes
MONTH(44805)
and returns 9.
Step 2 - Calculate logical expressions
The equal sign is a logical operator and lets you compare value to value in an Excel formula. The result is a boolean value TRUE or FALSE.
MONTH(B3)=1 evaluates to FALSE
MONTH(B3)=2 evaluates to FALSE
MONTH(B3)=3 evaluates to FALSE
MONTH(B3)=4 evaluates to FALSE
MONTH(B3)=5 evaluates to FALSE
MONTH(B3)=6 evaluates to FALSE
MONTH(B3)=7 evaluates to FALSE
MONTH(B3)=8 evaluates to FALSE
MONTH(B3)=9 evaluates to TRUE
MONTH(B3)=10 evaluates to FALSE
MONTH(B3)=11 evaluates to FALSE
MONTH(B3)=12 evaluates to FALSE
MONTH(B3)=9
becomes
9=9
and returns TRUE
Step 3 - Return the corresponding value
MONTH(B3)=1,"January",
MONTH(B3)=2, "February",
MONTH(B3)=3,"March",
MONTH(B3)=4, "April",
MONTH(B3)=5,"May",
MONTH(B3)=6, "June",
MONTH(B3)=7, "July",
MONTH(B3)=8,"August",
MONTH(B3)=9, "September",
MONTH(B3)=10, "October",
MONTH(B3)=11,"November",
MONTH(B3)=12, "December"
MONTH(B3)=9, "September"
becomes
TRUE, "September"
and returns "September" in cell C3.
6. Example 3 - find the element name based on an atomic number
The IFS function is great for smaller logical expressions but I recommend using a different formula combined with a table to avoid mega-formulas.
This example demonstrates this, the table in cell range E3:G116 describes the atomic numbers in the periodic table and the corresponding symbol and element name.
Creating a large IFS function for this specific example is possible, remember, you are allowed to use up to 127 pairs of logical expressions, however, I recommend putting all logical expressions and corresponding values in a table. This makes it easier to troubleshoot and examine the formula.
Formula in cell C3:
Explaining formula
The INDEX function returns a value from a cell range, you specify which value based on a row and column number.
INDEX(array, [row_num], [column_num], [area_num])
INDEX($G$3:$G$116, B3)
becomes
INDEX($G$3:$G$116, 57)
and returns the value in cell E59 which is "Lanthanum".
$G$3:$G$116 is an absolute cell reference meaning it won't change when you copy cell C3 and paste it to the cells below.
B3 is a relative cell reference meaning it changes when you copy cell C3 and paste it to the cells below.
7. Function not working
The IFS function returns #N/A! error if no logical expression is met. The image above demonstrates this in cells B5 and C5, cell B5 contains 45 which no logical expression evaluates to TRUE.
7.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.
7.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 logical expressions B5>50 and B5=50 converted to hard-coded values using the F9 key. The IFS function requires at least one logical expression evaluating to TRUE 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
7.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.
8. Get Excel file
Functions in 'Logical' category
The IFS function function is one of 16 functions in the 'Logical' 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