Многократное if в excel

The IF function allows you to make a logical comparison between a value and what you expect by testing for a condition and returning a result if True or False.

  • =IF(Something is True, then do something, otherwise do something else)

So an IF statement can have two results. The first result is if your comparison is True, the second if your comparison is False.

IF statements are incredibly robust, and form the basis of many spreadsheet models, but they are also the root cause of many spreadsheet issues. Ideally, an IF statement should apply to minimal conditions, such as Male/Female, Yes/No/Maybe, to name a few, but sometimes you might need to evaluate more complex scenarios that require nesting* more than 3 IF functions together.

* “Nesting” refers to the practice of joining multiple functions together in one formula.

Use the IF function, one of the logical functions, to return one value if a condition is true and another value if it’s false.

Syntax

IF(logical_test, value_if_true, [value_if_false])

For example:

  • =IF(A2>B2,»Over Budget»,»OK»)

  • =IF(A2=B2,B4-A4,»»)

Argument name

Description

logical_test   

(required)

The condition you want to test.

value_if_true   

(required)

The value that you want returned if the result of logical_test is TRUE.

value_if_false   

(optional)

The value that you want returned if the result of logical_test is FALSE.

Remarks

While Excel will allow you to nest up to 64 different IF functions, it’s not at all advisable to do so. Why?

  • Multiple IF statements require a great deal of thought to build correctly and make sure that their logic can calculate correctly through each condition all the way to the end. If you don’t nest your formula 100% accurately, then it might work 75% of the time, but return unexpected results 25% of the time. Unfortunately, the odds of you catching the 25% are slim.

  • Multiple IF statements can become incredibly difficult to maintain, especially when you come back some time later and try to figure out what you, or worse someone else, was trying to do.

If you find yourself with an IF statement that just seems to keep growing with no end in sight, it’s time to put down the mouse and rethink your strategy.

Let’s look at how to properly create a complex nested IF statement using multiple IFs, and when to recognize that it’s time to use another tool in your Excel arsenal.

Examples

Following is an example of a relatively standard nested IF statement to convert student test scores to their letter grade equivalent.

Complex nested IF statement - Formula in E2 is =IF(B2>97,"A+",IF(B2>93,"A",IF(B2>89,"A-",IF(B2>87,"B+",IF(B2>83,"B",IF(B2>79,"B-",IF(B2>77,"C+",IF(B2>73,"C",IF(B2>69,"C-",IF(B2>57,"D+",IF(B2>53,"D",IF(B2>49,"D-","F"))))))))))))

  • =IF(D2>89,»A»,IF(D2>79,»B»,IF(D2>69,»C»,IF(D2>59,»D»,»F»))))

    This complex nested IF statement follows a straightforward logic:

  1. If the Test Score (in cell D2) is greater than 89, then the student gets an A

  2. If the Test Score is greater than 79, then the student gets a B

  3. If the Test Score is greater than 69, then the student gets a C

  4. If the Test Score is greater than 59, then the student gets a D

  5. Otherwise the student gets an F

This particular example is relatively safe because it’s not likely that the correlation between test scores and letter grades will change, so it won’t require much maintenance. But here’s a thought – what if you need to segment the grades between A+, A and A- (and so on)? Now your four condition IF statement needs to be rewritten to have 12 conditions! Here’s what your formula would look like now:

  • =IF(B2>97,»A+»,IF(B2>93,»A»,IF(B2>89,»A-«,IF(B2>87,»B+»,IF(B2>83,»B»,IF(B2>79,»B-«, IF(B2>77,»C+»,IF(B2>73,»C»,IF(B2>69,»C-«,IF(B2>57,»D+»,IF(B2>53,»D»,IF(B2>49,»D-«,»F»))))))))))))

It’s still functionally accurate and will work as expected, but it takes a long time to write and longer to test to make sure it does what you want. Another glaring issue is that you’ve had to enter the scores and equivalent letter grades by hand. What are the odds that you’ll accidentally have a typo? Now imagine trying to do this 64 times with more complex conditions! Sure, it’s possible, but do you really want to subject yourself to this kind of effort and probable errors that will be really hard to spot?

Tip: Every function in Excel requires an opening and closing parenthesis (). Excel will try to help you figure out what goes where by coloring different parts of your formula when you’re editing it. For instance, if you were to edit the above formula, as you move the cursor past each of the ending parentheses “)”, its corresponding opening parenthesis will turn the same color. This can be especially useful in complex nested formulas when you’re trying to figure out if you have enough matching parentheses.

Additional examples

Following is a very common example of calculating Sales Commission based on levels of Revenue achievement.

Formula in cell D9 is IF(C9>15000,20%,IF(C9>12500,17.5%,IF(C9>10000,15%,IF(C9>7500,12.5%,IF(C9>5000,10%,0)))))

  • =IF(C9>15000,20%,IF(C9>12500,17.5%,IF(C9>10000,15%,IF(C9>7500,12.5%,IF(C9>5000,10%,0)))))

This formula says IF(C9 is Greater Than 15,000 then return 20%, IF(C9 is Greater Than 12,500 then return 17.5%, and so on…

While it’s remarkably similar to the earlier Grades example, this formula is a great example of how difficult it can be to maintain large IF statements – what would you need to do if your organization decided to add new compensation levels and possibly even change the existing dollar or percentage values? You’d have a lot of work on your hands!

Tip: You can insert line breaks in the formula bar to make long formulas easier to read. Just press ALT+ENTER before the text you want to wrap to a new line.

Here is an example of the commission scenario with the logic out of order:

Formula in D9 is out of order as =IF(C9>5000,10%,IF(C9>7500,12.5%,IF(C9>10000,15%,IF(C9>12500,17.5%,IF(C9>15000,20%,0)))))

Can you see what’s wrong? Compare the order of the Revenue comparisons to the previous example. Which way is this one going? That’s right, it’s going from bottom up ($5,000 to $15,000), not the other way around. But why should that be such a big deal? It’s a big deal because the formula can’t pass the first evaluation for any value over $5,000. Let’s say you’ve got $12,500 in revenue – the IF statement will return 10% because it is greater than $5,000, and it will stop there. This can be incredibly problematic because in a lot of situations these types of errors go unnoticed until they’ve had a negative impact. So knowing that there are some serious pitfalls with complex nested IF statements, what can you do? In most cases, you can use the VLOOKUP function instead of building a complex formula with the IF function. Using VLOOKUP, you first need to create a reference table:

Formula in cell D2 is =VLOOKUP(C2,C5:D17,2,TRUE)

  • =VLOOKUP(C2,C5:D17,2,TRUE)

This formula says to look for the value in C2 in the range C5:C17. If the value is found, then return the corresponding value from the same row in column D.

Formula in cell C9 is =VLOOKUP(B9,B2:C6,2,TRUE)

  • =VLOOKUP(B9,B2:C6,2,TRUE)

Similarly, this formula looks for the value in cell B9 in the range B2:B22. If the value is found, then return the corresponding value from the same row in column C.

Note: Both of these VLOOKUPs use the TRUE argument at the end of the formulas, meaning we want them to look for an approxiate match. In other words, it will match the exact values in the lookup table, as well as any values that fall between them. In this case the lookup tables need to be sorted in Ascending order, from smallest to largest.

VLOOKUP is covered in much more detail here, but this is sure a lot simpler than a 12-level, complex nested IF statement! There are other less obvious benefits as well:

  • VLOOKUP reference tables are right out in the open and easy to see.

  • Table values can be easily updated and you never have to touch the formula if your conditions change.

  • If you don’t want people to see or interfere with your reference table, just put it on another worksheet.

Did you know?

There is now an IFS function that can replace multiple, nested IF statements with a single function. So instead of our initial grades example, which has 4 nested IF functions:

  • =IF(D2>89,»A»,IF(D2>79,»B»,IF(D2>69,»C»,IF(D2>59,»D»,»F»))))

It can be made much simpler with a single IFS function:

  • =IFS(D2>89,»A»,D2>79,»B»,D2>69,»C»,D2>59,»D»,TRUE,»F»)

The IFS function is great because you don’t need to worry about all of those IF statements and parentheses.

Need more help?

You can always ask an expert in the Excel Tech Community or get support in the Answers community.

Related Topics

Video: Advanced IF functions

IFS function (Microsoft 365, Excel 2016 and later)

The COUNTIF function will count values based on a single criteria

The COUNTIFS function will count values based on multiple criteria

The SUMIF function will sum values based on a single criteria

The SUMIFS function will sum values based on multiple criteria

AND function

OR function

VLOOKUP function

Overview of formulas in Excel

How to avoid broken formulas

Detect errors in formulas

Logical functions

Excel functions (alphabetical)

Excel functions (by category)

The IF function is an extremely powerful tool that gives you the ability to manipulate and analyze your Excel data based on conditions. This statement stems from the logical use of “IF” to base the value of one cell off of conditions that exist in one or more other cells.

We use the word “if” in everyday life to make decisions in the same way that Excel uses the IF function to make decisions based on your data. In real life, for instance, we may decide that “if” we get a raise, we will take a vacation. This statement relies on us evaluating the condition and then taking action based on that evaluation in the same way that Excel examines a condition and then takes further steps based on its assessment.

Excel gives you even more power over the data in your spreadsheets by allowing you to use multiple IF statements in the same expression. This tutorial will show you how to use them in your worksheets. To get the maximum value from this tutorial, you first need to know how to use the basic Excel functions and features.

The Basic IF Function in Excel

The basic IF function in Excel evaluates a condition and then performs a number of steps based on the result of that evaluation. Look at the chart below to see a visual representation of the logic behind the IF function.

Illustration of basic if function

As the image above suggests, we use the IF statement to evaluate a condition. If the statement returns true, then one value is returned. If the statement returns false, then another value is returned. Let’s look at the syntax of the IF statement.

Microsoft Excel IF syntax

Here is the syntax of the IF statement in Excel:

IF(condition, value_if_true, value_if_false)

Here are the details on the parameters:

•      condition: The value that you want to test.

•      value_if_true: The value that is returned if condition evaluates to TRUE.

•      value_if_false: The value that is returned if condition evaluates to FALSE.

To get a sense of how this works, we can convert it to pseudocode like the example below:

IF (condition) THEN
  value_if_true
ELSE
  value_if_false
END IF

The third parameter in the Excel IF statement is equivalent to what an ELSE statement would return in many programming languages, but you can also use another IF statement as the third parameter. This structure means that you could create an IF statement, and then if that statement evaluates to true, the code can then use another IF statement and so on.

Here is what a nested IF statement would look like:

IF(condition1, value_if_true1, IF(condition2, value_if_true2, value_if_false2))

We can look at this as pseudocode again to figure out what is happening.

IF condition1 THEN
   value_if_true1
ELSEIF condition2 THEN
   value_if_true2
ELSE
   value_if_false2
END IF

With the current version of Excel, you can nest up to 64 different IF functions — which is basically like chaining a bunch of ELSEIF conditions in a programming language. Note, though, that just because it’s possible to nest a large amount of IF statements, doesn’t mean it’s a good idea. We’ll explain the reason behind that later in the article, but for now, let’s look at some examples of how nested IF statements can help you perf data analytics.

Before we get into using multiple IF statements, let’s get started with a simple example of using only one IF statement and build from there.

Using the IF Statement in Excel

For our following examples, imagine you’re a teacher who needs to assign a grade to each student based on their test scores. You have the names of the students and their test scores in a spreadsheet. Here is an sample of the type of data you will have:

Name Test Score
Bob 42
Sue 65
Joe 85
Pam 90
John 67
Cindy 75
Jim 55
Nancy 77
Will 68

Let’s be lenient with the students and say that any student getting over 50% of the questions right passes. Below, you can see what our data looks like in an Excel spreadsheet. We also added a Pass/Fail column for the IF function we will be using.

data in spreadsheet

After you have your data in the spreadsheet, select the top cell in the Pass/Fail column and click on the Fx button to add a function to the cell. This is the function that will print “Pass” or “Fail” in the column:

IF(B2 > 50, "Pass", "Fail")

You can add that behind the equals sign. This basically says if the value in the B2 cell is greater than 50, then print “Pass.” If not, print “Fail.” To add the function to the rest of the cells in the column, just highlight and drag the cell down the column, and it will create functions for each cell. If you click on them, you will notice the only thing that changes is the cell value in the function. The following function in the next cell down will be this:

IF(B3 > 50, "Pass", "Fail")

That was a simple example, but it shows how valuable the IF function can be in Excel. Imagine having to determine a pass or fail in a list of a hundred students just by looking at the Test Score column. Let’s take this a little further and give the students letter grades instead of simply passing or failing them. This will give us a chance to use nested IF statements.

Using a Nested IF Statement in Excel

You have decided that pass and fail are not enough. You need to assign letter grades to the students. Here is how you will determine that. If a student gets a test score under 50, then they get an “E” grade. If a student scores between 50 and 60, they get a “D.” If the score is between 60 and 70, they get a “C.” With a score between 70 and 80, they get a “B,” and with a score of 80 or more, they get an “A.”

This is what our new student spreadsheet will look like:

image of student score spreadsheet

We will use the IF statement syntax to create the various conditions needed to assign the different grades required.

Essentially, we will create an “IF” statement that checks if the test is 50 or lower. If the condition is true, we will assign a grade of “E” to that student. If the condition is false, we will use a new IF statement to create a new condition that checks if the grade is between 50 and 60. If this condition is true, it will assign a “D” grade, but if the condition is false, we will need to create a new IF statement to check the new conditions. In this way, we will create multiple IF statements to check for all the conditions required to assign the student’s correct grade.

This is what the Excel formula for checking each condition using the multiple IF statements looks like:

IF(B2 < 50, "E", IF(B2 < 60, "D", IF(B2 < 70, "C", IF(B2 < 80, "B", IF(B2 < 100, "A")))))

Multiple IF statements in Excel can be hard to create and can become incredibly complex to follow. A good rule to follow when creating multiple IF statements is to write the statement in plain English first. This will help you create a logical structure that you can use to create your Excel IF statement. Another option is to use pseudocode, as was done in the syntax section. For our nested IF formula, it would look like this:

IF B2 < 50 THEN
   "E"
ELSEIF B2 < 60 THEN
   "D"
ELSEIF B2 < 70 THEN
   "C"
ELSEIF B2 < 80 THEN
   "B"
ELSEIF B2 < 100 THEN
   "A"
END IF

The resulting worksheet will look like this:

image of worksheet with names, test scores, grades

Avoiding Issues with Multiple IF Statements

Microsoft Excel will allow you to nest up to 64 IF statements, but you really wouldn’t want to do that. Reasons for this include:

•      Multiple IF statements take some work to create. It is hard to remember what you are doing when you are nesting a lot of IF statements. It was hard to tell what our IF statement was doing to calculate the letter grades, and there were only four nested IF statements there. Imagine if there were 64.

•      Multiple IF statements can be hard to maintain. You may know how they work when you initially create them, but what about if you have to come back months later to edit them? And what if someone else gets the job of modifying them? It will take time to determine what you were trying to do in the first place.

•      Even though you can use 64 nested IF functions in Excel versions created after 2007, older versions of Excel don’t allow that much nesting. Excel 2003 only supports seven nested IF functions.

If the IF statements in your Excel spreadsheet are too long, it might be time to rethink how you are creating your spreadsheet. Reorganizing the data and using other Excel functions like SWITCH may be the answer.

Alternatives to Nested IF Statements

Multiple IF statements can give you a lot of power, but they can get out of hand. There are quite a few Excel formulas that can replace multiple nested IF statements in the right situation. Let’s look at a few of the options.

The SWITCH Function

The SWITCH function would not have worked for the letter grades spreadsheet we have because we are using a range as our conditions. However, the SWITCH statement can function as a concise form of the nested IF statement for pre-defined values. If, for example, we wanted to base another column in the spreadsheet off of the letter grades, a SWITCH statement would be perfect for the job. Let’s say that we want to assign each student to a room number based on their letter grades. If we wrote a nested IF statement to do this, it would look like this:

IF(C2 = "A", 100, IF(C2 = "B", 101, IF(C2 = "C", 102, IF(C2 = "D", 103, IF(C2 = "E", 104)))))

Because we are looking for a specific value in the IF function, we can replace this with a SWITCH function. The syntax of the SWITCH function is the following:

SWITCH(expression, value1, result1, value2, result2, …, [default])

The SWITCH function evaluates the value in the expression parameter. If it matches value1, then result1 is returned. If it matches value2, then result2 is returned, and so on. So to replace the nested IF statement above, we would use the following SWITCH statement:

SWITCH(C3, "A", 100, "B", 101, "C", 102, "D", 103, "E", 104)

This statement checks the C3 cell, and if it contains “A,” then we set the value to 100. If it is “B,” we set it to 101, and so on. The SWITCH function made its debut in Excel 2016. For older versions of Excel, you can concatenate multiple IF statements.

Concatenating Multiple IF Functions in Excel

To do something similar to the SWITCH statement in versions of Excel that released before 2016, you can concatenate multiple IF statements using the ampersand or CONCATENATE function instead of nesting them. This only works where a SWITCH statement would work. The values we are evaluating have to be pre-defined and not a range. The following expression could replace the SWITCH statement above:

(IF(C2 = "A", 100, "") & IF(C2 = "B", 101, "") & IF(C2="C", 102, "") & IF(C2="D", 103, "") & IF(C2="C", 104, ""))

We could also replace it with this:

CONCATENATE(IF(C2 = "A", 100, ""), IF(C2 = "B", 101, ""), IF(C2="C", 102, ""), IF(C2="D", 103, ""), IF(C2="C", 104, ""))

These statements are still pretty lengthy, but they aren’t nested, making them simpler to read.

The IFS Function

Another feature of Microsoft Excel 2016 and later versions is the IFS function. You can use it to evaluate multiple conditions. Here is the syntax of the IFS function:

IFS(logical_test1, value_if_true1, [logical_test2, value_if_true2]...)

This syntax is like the SWITCH function’s syntax, but the IFS function allows ranges. If the logical test evaluates to true, then the formula will return the matching value.  We can use it to replace the expression we used initially to add the letter grades to the grades column. Here is that expression again:

IF(B2 < 50, "E", IF(B2 < 60, "D", IF(B2 < 70, "C", IF(B2 < 80, "B", IF(B2 < 100, "A")))))

We can create a formula like this to replace it:

IFS(B2 < 50, "E", B2 < 60, "D", B2 < 70, "C", B2 < 80, "B", B2 < 100, "A")

The CHOOSE Function

You can also use the CHOOSE function to replace multiple IF statements in your Excel spreadsheets. The syntax of the CHOOSE function is a little more advanced than the functions we have covered so far. Here is that syntax:

CHOOSE(index_num, value1, [value2], [value3], [value4], ...)

The value of the index_num determines the return value. If the index_num is 1, then it returns value1. If the index_num is 2, then it returns value2, and so on. Here is how to do it for our letter grade formula:

CHOOSE((B2 < 60) + (B2 < 70)+ (B2 < 80)+ (B2 < 90)+ (B2 < 100), "A", "B", "C", "D", "E")

This expression works because TRUE = 1 and FALSE = 0 in Excel. So if a student got a 95, only the B2 < 100 expression would evaluate to TRUE. All the rest would be FALSE. This would make the index_num equal to 1 + 0 + 0 + 0 + 0 or 1. This would evaluate the value in the value1 parameter or “A.” If a student got a 50, then all the expressions in the index_num parameter would add up to 5, which results in an “E.”

Conclusion

The IF function is a powerful tool you can use in your Excel spreadsheets. You can use it for data analysis, conditional labeling of data, and more. The fact that you can nest IF statements gives you even more control over the conditionals in your spreadsheets, along with the ability to compare more than two values against each other. Nested IFs can become hard to manage, but there are Excel functions you can use in place of multiple IF statements, including SWITCH, IFS, and CHOOSE. Nonetheless, you still can’t beat the IF statement for flexibility. 

Now that you know how to use multiple IF statements in Excel, let’s learn about the VLOOKUP function, another one of the most important Excel skills to have.

Multiple IF Conditions in Excel

The multiple IF conditions in Excel are IF statements contained within another IF statement. They are used to test multiple conditions simultaneously and return distinct values. The additional IF statements can be included in the “value if true” and “value if false” arguments of a standard IF formula.

For example, suppose we have a dataset of students’ scores from B1:B12. We need to grade the students according to their scores. Then, using the IF condition, we can manage the multiple conditions. In this example, we can insert the nested IF formula in cell D1 to assign a grade to a score. We can grade total score as “A,” “B,” “C,” “D,” and “F.” A score would be “F” if it is greater than or equal to 30, “D” if it is greater than 60, and “C” if it is greater than or equal to 70, and “A,” “B” if the score is less than 95. We can insert the formula in D1 with 5 separate IF functions:

=IF(B1>30,”F”,IF(B1>60,”D”,IF(B1>70,”C”,IF(C5>80,”B”,”A”))))

Table of contents
  • Multiple IF Condition in Excel
    • Explanation
    • Examples
      • Example #1
      • Example #2
      • Example #3
      • Example #4
    • Things to Remember
    • Recommended Articles

Explanation

The IF formula is used when we wish to test a condition and return one value if the condition is met and another value if it is not met.

Each subsequent IF formula is incorporated into the “value_if_false” argument of the previous IF. So, the nested IF excelIn Excel, nested if function means using another logical or conditional function with the if function to test multiple conditions. For example, if there are two conditions to be tested, we can use the logical functions AND or OR depending on the situation, or we can use the other conditional functions to test even more ifs inside a single if.read more formula works as follows:

multiple Conditions

Syntax

IF (condition1, result1, IF (condition2, result2, IF (condition3, result3,………..)))

Examples

You can download this Multiple Ifs Excel Template here – Multiple Ifs Excel Template

Example #1

Suppose we wish to find how a student scores in an exam. There are two exam scores of a student, and we define the total score (sum of the two scores) as “Good,” “Average,” and “Bad.” A score would be “Good” if it is greater than or equal to 60, ‘Average’ if it is between 40 and 60, and ‘Bad’ if it is less than or equal to 40.

Let us say the first score is stored in column B, the second in column C.

Multiple ifs Example 1

The following formula tells Excel to return “Good,” “Average,” or “Bad”:

=IF(D2>=60,”Good”,IF(D2>40,”Average”,”Bad”))

Multiple ifs Example 1-1

This formula returns the result as given below:

Multiple ifs Example 1-2

Drag the formula to get results for the rest of the cells.

We can see that one multiple IF function is sufficient in this case as we need to get only 3 results.

Multiple ifs Example 1-3

We can see that one multiple IF function is sufficient in this case as we need to get only 3 results.

Example #2

We want to test one more condition in the above examples: the total score of 70 and above is categorized as “Excellent.”

=IF(D2>=70,”Excellent”,IF(D2>=60,”Good”,IF(D2>40,”Average”,”Bad”)))

Multiple ifs Example 2

This formula returns the result as given below:

Multiple ifs Example 2-1

Excellent: >=70

Good: Between 60 & 69

Average: Between 41 & 59

Bad: <=40

Drag the formula to get results for the rest of the cells.

Multiple ifs Example 2-2

We can add several “IF” conditions if required similarly.

Example #3

Suppose we wish to test a few sets of different conditions. In that case, those conditions can be expressed using logical OR and AND, nesting the functions inside IF statements and then nesting the IF statements into each other.

For instance, if we have two columns containing the number of targets made by an employee in 2 quarters: Q1 and Q2. Then, we wish to calculate the performance bonus of the employee based on a higher target number.

Multiple ifs Example 3

We can make a formula with the logic:

  1. If either Q1 or Q2 targets are greater than 70, then the employee gets a 10% bonus,
  2. If either of them is greater than 60, then the employee receives a 7% bonus,
  3. If either of them is greater than 50, then the employee gets a 5% bonus,
  4. If either is greater than 40, then the employee receives a 3% bonus. Else, no bonus.

So, we first write a few OR statements like (B2>=70,C2>=70), and then nest them into logical tests of IF functions as follows:

=IF(OR(B2>=70,C2>=70),10%,IF(OR(B2>=60,C2>=60),7%, IF(OR(B2>=50,C2>=50),5%, IF(OR(B2>=40,C2>=40),3%,””))))

Multiple ifs Example 3-1

This formula returns the result as given below:

Multiple ifs Example 3-2

Next, drag the formula to get the results of the rest of the cells.

Multiple ifs Example 3-3

Example #4

Now, let us say we want to test one more condition in the above example:

  1. If both Q1 and Q2 targets are greater than 70, then the employee gets a 10% bonus
  2. if both of them are greater than 60, then the employee receives a 7% bonus
  3. if both of them are greater than 50, then the employee gets a 5% bonus
  4. if both of them are greater than 40, then the employee receives a 3% bonus
  5. Else, no bonus.

So, we first write a few AND statements like (B2>=70,C2>=70), and then nest them: tests of IF functions as follows:

=IF(AND(B2>=70,C2>=70),10%,IF(AND(B2>=60,C2>=60),7%, IF(AND(B2>=50,C2>=50),5%, IF(AND(B2>=40,C2>=40),3%,””))))

Multiple ifs Example 4

This formula returns the result as given below:

Multiple ifs Example 4-1

Next, drag the formula to get results for the rest of the cells.

Drag Example 4-2

Things to Remember

  • The multiple IF function evaluates the logical tests in the order they appear in a formula. So, for example, as soon as one condition evaluates to be “True,” the following conditions are not tested.
    • For instance, if we consider the second example discussed above, the multiple IF condition in Excel evaluates the first logical test (D2>=70) and returns “Excellent” because the condition is “True” in the below formula:

=IF(D2>=70,”Excellent”,IF(D2>=60,,”Good”,IF(D2>40,”Average”,”Bad”))

Now, if we reverse the order of IF functions in Excel as follows:

=IF(D2>40,”Average”,IF(D2>=60,,”Good”,IF(D2>=70,”Excellent”,”Bad”))

In this case, the formula tests the first condition. Since 85 is greater than or equal to 70, a result of this condition is also “True,” so the formula would return “Average” instead of “Excellent” without testing the following conditions.

Correct Order

Correct Order

Incorrect Order

InCorrect Order

Note: Changing the order of the IF function in Excel would change the result.

  • Evaluate the formula logic– To see the step-by-step evaluation of multiple IF conditions, we can use the ‘Evaluate Formula’ feature in excel on the “Formula” tab in the “Formula Auditing” group. Clicking the “Evaluate” button will show all the steps in the evaluation process.
  • For instance, in the second example, the evaluation of the first logical testA logical test in Excel results in an analytical output, either true or false. The equals to operator, “=,” is the most commonly used logical test.read more of multiple IF formulas will go as D2>=70; 85>=70; True; Excellent.

Evaluate

  • Balancing the parentheses: If the parentheses do not match in terms of number and order, then the multiple IF formula would not work.
    • If we have more than one set of parentheses, the parentheses pairs are shaded in different colors so that the opening parentheses match the closing ones.
    • Also, on closing the parenthesis, the matching pair is highlighted.
  • Numbers and Text should be treated differently: The text should always be enclosed in double quotes in the multiple IF formula.
  • Multiple IF’s can often become troublesome: Managing many true and false conditions and closing brackets in one statement becomes difficult. Therefore, it is always good to use other tools like IF function or VLOOKUP in case Multiple IF’sSometimes while working with data, when we match the data to the reference Vlookup, it finds the first value and does not look for the next value. However, for a second result, to use Vlookup with multiple criteria, we need to use other functions with it.read more are difficult to maintain in Excel.

Recommended Articles

This article is a guide to Multiple IF Conditions in Excel. We discuss using multiple IF conditions, practical examples, and a downloadable Excel template. You may also learn more about Excel from the following articles: –

  • IF OR in VBAIF OR is not a single statement; it is a pair of logical functions used together in VBA when we have more than one criteria to check, and when we use the if statement, we receive the true result if either of the criteria is met.read more
  • COUNTIF in ExcelThe COUNTIF function in Excel counts the number of cells within a range based on pre-defined criteria. It is used to count cells that include dates, numbers, or text. For example, COUNTIF(A1:A10,”Trump”) will count the number of cells within the range A1:A10 that contain the text “Trump”
    read more
  • IFERROR Excel Function – ExamplesThe IFERROR function in Excel checks a formula (or a cell) for errors and returns a specified value in place of the error.read more
  • SUMIF Excel FunctionThe SUMIF Excel function calculates the sum of a range of cells based on given criteria. The criteria can include dates, numbers, and text. For example, the formula “=SUMIF(B1:B5, “<=12”)” adds the values in the cell range B1:B5, which are less than or equal to 12.
    read more

This Excel tutorial explains how to nest the Excel IF function with syntax and examples.

Description

The IF function is a built-in function in Excel that is categorized as a Logical Function. It can be used as a worksheet function (WS) in Excel. As a worksheet function, the IF function can be entered as part of a formula in a cell of a worksheet.

It is possible to nest multiple IF functions within one Excel formula. You can nest up to 7 IF functions to create a complex IF THEN ELSE statement.

TIP: If you have Excel 2016, try the new IFS function instead of nesting multiple IF functions.

Syntax

The syntax for the nesting the IF function is:

IF( condition1, value_if_true1, IF( condition2, value_if_true2, value_if_false2 ))

This would be equivalent to the following IF THEN ELSE statement:

IF condition1 THEN
   value_if_true1
ELSEIF condition2 THEN
   value_if_true2
ELSE
   value_if_false2
END IF

Parameters or Arguments

condition
The value that you want to test.
value_if_true
The value that is returned if condition evaluates to TRUE.
value_if_false
The value that is return if condition evaluates to FALSE.

Example (as Worksheet Function)

Let’s look at an example to see how you would use a nested IF and explore how to use the nested IF function as a worksheet function in Microsoft Excel:

Microsoft Excel

Based on the Excel spreadsheet above, the following Nested IF examples would return:

=IF(A1="10x12",120,IF(A1="8x8",64,IF(A1="6x6",36)))
Result: 120

=IF(A2="10x12",120,IF(A2="8x8",64,IF(A2="6x6",36)))
Result: 64

=IF(A3="10x12",120,IF(A3="8x8",64,IF(A3="6x6",36)))
Result: 36

TIP: When nesting multiple IF functions, DO NOT start the second IF function with = sign.

Incorrect formula:
=IF(A1=2,»Hello»,=IF(A1=3,»Goodbye»,0))

Correct formula
=IF(A1=2,»Hello»,IF(A1=3,»Goodbye»,0))

Frequently Asked Questions

Question: In Microsoft Excel, I need to write a formula that works this way:

If (cell A1) is less than 20, then multiply by 1,
If it is greater than or equal to 20 but less than 50, then multiply by 2
If its is greater than or equal to 50 and less than 100, then multiply by 3
And if it is great or equal to than 100, then multiply by 4

Answer: You can write a nested IF statement to handle this. For example:

=IF(A1<20, A1*1, IF(A1<50, A1*2, IF(A1<100, A1*3, A1*4)))

Question:In Excel, I need a formula in cell C5 that does the following:

IF A1+B1 <= 4, return $20
IF A1+B1 > 4 but <= 9, return $35
IF A1+B1 > 9 but <= 14, return $50
IF A1+B1 > 15, return $75

Answer:In cell C5, you can write a nested IF statement that uses the AND function as follows:

=IF((A1+B1)<=4,20,IF(AND((A1+B1)>4,(A1+B1)<=9),35,IF(AND((A1+B1)>9,(A1+B1)<=14),50,75)))

Question: In Microsoft Excel, I need a formula for the following:

IF cell A1= PRADIP then value will be 100
IF cell A1= PRAVIN then value will be 200
IF cell A1= PARTHA then value will be 300
IF cell A1= PAVAN then value will be 400

Answer: You can write an IF statement as follows:

=IF(A1="PRADIP",100,IF(A1="PRAVIN",200,IF(A1="PARTHA",300,IF(A1="PAVAN",400,""))))

Question: In Microsoft Excel, I want to calculate following using an «if» formula:

if A1<100,000 then A1*.1% but minimum 25
and if A1>1,000,000 then A1*.01% but maximum 5000

Answer: You can write a nested IF statement that uses the MAX function and the MIN function as follows:

=IF(A1<100000,MAX(25,A1*0.1%),IF(A1>1000000,MIN(5000,A1*0.01%),""))

Question:I have Excel 2000. If cell A2 is greater than or equal to 0 then add to C1. If cell B2 is greater than or equal to 0 then subtract from C1. If both A2 and B2 are blank then equals C1. Can you help me with the IF function on this one?

Answer: You can write a nested IF statement that uses the AND function and the ISBLANK function as follows:

=IF(AND(ISBLANK(A2)=FALSE,A2>=0),C1+A2, IF(AND(ISBLANK(B2)=FALSE,B2>=0),C1-B2, IF(AND(ISBLANK(A2)=TRUE, ISBLANK(B2)=TRUE),C1,"")))

Question:How would I write this equation in Excel? If D12<=0 then D12*L12, If D12 is > 0 but <=600 then D12*F12, If D12 is >600 then ((600*F12)+((D12-600)*E12))

Answer: You can write a nested IF statement as follows:

=IF(D12<=0,D12*L12,IF(D12>600,((600*F12)+((D12-600)*E12)),D12*F12))

Question:I have read your piece on nested IFs in Excel, but I still cannot work out what is wrong with my formula please could you help? Here is what I have:

=IF(63<=A2<80,1,IF(80<=A2<95,2,IF(A2=>95,3,0)))

Answer: The simplest way to write your nested IF statement based on the logic you describe above is:

=IF(A2>=95,3,IF(A2>=80,2,IF(A2>=63,1,0)))

This formula will do the following:

If A2 >= 95, the formula will return 3 (first IF function)
If A2 < 95 and A2 >= 80, the formula will return 2 (second IF function)
If A2 < 80 and A2 >= 63, the formula will return 1 (third IF function)
If A2 < 63, the formula will return 0


Question:I’m very new to the Excel world, and I’m trying to figure out how to set up the proper formula for an If/then cell.

What I’m trying for is:

If B2’s value is 1 to 5, then multiply E2 by .77
If B2’s value is 6 to 10, then multiply E2 by .735
If B2’s value is 11 to 19, then multiply E2 by .7
If B2’s value is 20 to 29, then multiply E2 by .675
If B2’s value is 30 to 39, then multiply E2 by .65

I’ve tried a few different things thinking I was on the right track based on the IF, and AND function tutorials here, but I can’t seem to get it right.

Answer:To write your IF formula, you need to nest multiple IF functions together in combination with the AND function.

The following formula should work for what you are trying to do:

=IF(AND(B2>=1, B2<=5), E2*0.77, IF(AND(B2>=6, B2<=10), E2*0.735, IF(AND(B2>=11, B2<=19), E2*0.7, IF(AND(B2>=20, B2<=29), E2*0.675, IF(AND(B2>=30, B2<=39), E2*0.65,"")))))

As one final component of your formula, you need to decide what to do when none of the conditions are met. In this example, we have returned «» when the value in B2 does not meet any of the IF conditions above.


Question:I have a nesting OR function problem:

My nonworking formula is:

=IF(C9=1,K9/J7,IF(C9=2,K9/J7,IF(C9=3,K9/L7,IF(C9=4,0,K9/N7))))

In Cell C9, I can have an input of 1, 2, 3, 4 or 0. The problem is on how to write the «or» condition when a «4 or 0» exists in Column C. If the «4 or 0» conditions exists in Column C I want Column K divided by Column N and the answer to be placed in Column M and associated row

Answer:You should be able to use the OR function within your IF function to test for C9=4 OR C9=0 as follows:

=IF(C9=1,K9/J7,IF(C9=2,K9/J7,IF(C9=3,K9/L7,IF(OR(C9=4,C9=0),K9/N7))))

This formula will return K9/N7 if cell C9 is either 4 or 0.


Question:In Excel, I am trying to create a formula that will show the following:

If column B = Ross and column C = 8 then in cell AB of that row I want it to show 2013, If column B = Block and column C = 9 then in cell AB of that row I want it to show 2012.

Answer:You can create your Excel formula using nested IF functions with the AND function.

=IF(AND(B1="Ross",C1=8),2013,IF(AND(B1="Block",C1=9),2012,""))

This formula will return 2013 as a numeric value if B1 is «Ross» and C1 is 8, or 2012 as a numeric value if B1 is «Block» and C1 is 9. Otherwise, it will return blank, as denoted by «».


Question:In Excel, I really have a problem looking for the right formula to express the following:

If B1=0, C1 is equal to A1/2
If B1=1, C1 is equal to A1/2 times 20%
If D1=1, C1 is equal to A1/2-5

I’ve been trying to look for any same expressions in your site. Please help me fix this.

Answer:In cell C1, you can use the following Excel formula with 3 nested IF functions:

=IF(B1=0,A1/2, IF(B1=1,(A1/2)*0.2, IF(D1=1,(A1/2)-5,"")))

Please note that if none of the conditions are met, the Excel formula will return «» as the result.


Question:In Excel, what have I done wrong with this formula?

=IF(OR(ISBLANK(C9),ISBLANK(B9)),"",IF(ISBLANK(C9),D9-TODAY(), "Reactivated"))

I want to make an event that if B9 and C9 is empty, the value would be empty. If only C9 is empty, then the output would be the remaining days left between the two dates, and if the two cells are not empty, the output should be the string ‘Reactivated’.

The problem with this code is that IF(ISBLANK(C9),D9-TODAY() is not working.

Answer:First of all, you might want to replace your OR function with the AND function, so that your Excel IF formula looks like this:

=IF(AND(ISBLANK(C9),ISBLANK(B9)),"",IF(ISBLANK(C9),D9-TODAY(),"Reactivated"))

Next, make sure that you don’t have any abnormal formatting in the cell that contains the results. To be safe, right click on the cell that contains the formula and choose Format Cells from the popup menu. When the Format Cells window appears, select the Number tab. Choose General as the format and click on the OK button.


Question:I’m looking to return an answer from a number ‘n’ that needs to satisfy a certain range criteria. New stamp duty calculators for UK property set bands for percentage stamp duty as follows:

0-125000 =0%
125001-250000 =2%
250001-975000 =5%
975001-1500000 =10%
>1500000 =12%

I realise it’s probably an ‘IF(AND)’ function but I appear to require too many arguments. Can you help?

Answer:You can create this formula using nested IF functions. We will assume that your number ‘n’ resides in cell B1. You can create your formula as follows:

=IF(B1>1500000,B1*0.12, IF(B1>=975001,B1*0.1, IF(B1>=250001,B1*0.05, IF(B1>=125001,B1*0.02,0))))

Since your IF conditions will cover all numbers in the range of 0 to >1500000, it is easiest to work backwards starting with the >1500000 condition. Excel will evaluate each condition and stop when a condition is TRUE. This is why we can simplify the formulas within the nested IF functions, instead of testing ranges using two comparisons such as AND(B1>=125001, B1<=250000).


Question:Let’s expand the last question further and assume that we need to calculate percentages based on tiers (not just on the value as whole):

0-125000 =0%
125001-250000 =2%
250001-975000 =5%
975001-1500000 =10%
>1500000 =12%

Say I enter 1,000,000 in B1. The first 125,000 attracts 0%, the next 125,000 to 250,000 attracts 2%, and so on.

Answer:This adds a level of complexity to our formula since we have to calculate each range of the number using a different percentage.

We can create this solution with the following formula:

=IF(B1<=125000,0, IF(B1<=250000,(B1-125000)*0.02, IF(B1<=975000,(125000*0.02)+((B1-250000)*0.05), IF(B1<=1500000,(125000*0.02)+(725000*0.05)+((B1-975000)*0.1), (125000*0.02)+(725000*0.05)+(525000*0.1)+((B1-1500000)*0.12)))))

If the value was below 125,000, the formula would return 0.

If the value is between 125,001 and 250,000, it would calculate 0% on the first 125,000 and 2% on the remainder.

If the value is between 250,001 and 250,001, it would calculate 0% on the first 125,000, 2% on the next 125,000 and 5% on the remainder.

And so on….

If Function Excel Tutorial – And How to do Multiple If Statements in Excel

The IF function in Excel is an inestimable ally when we need to implement conditional logic, that is when we need different results depending on a condition.

The syntax is IF(logical_test, [value_if_true], [value_if_false]), where

  • logical_test is an expression that evaluates to TRUE or FALSE,
  • value_if_true is an optional argument, and it is what the expression evaluates to in case logical_test is true, and
  • value_if_false is an optional argument that determines the value in the case that logical_test is false.

image-39

How to conditionally set the value of a cell in Excel

Let’s see the if statement in action in the simplest use case, when the value of a cell is determined between two options based on the value of a different cell.

For example, let’s say that we have a list of projects, the percentage progress on each of them, and we want to automatically set the string to «In progress» or «Finished». Then we can write IF(B2=100, "Finished", "In progress") (where B2 is the first cell with the progress).

After writing the formula in the first cell we can just double click on the green handle that appears when the cell is selected and the formula will populate to all other cells in the column.

single-if

How to use a nested if statement to conditionally set the value of a cell with more options in Excel

Continuing from the example above, we may want to break down the progress status even more. This time we want to have 7 different status strings depending on the progress of the project.

We need to use nested if statements, writing an if statement in place of value_if_false (it can be used also in place of value_if_true but it becomes messier).

Let’s try to build a formula in case we want to have all these progress statuses: Not Started, Started, First Half, Halfway Through, Second Half, Almost Finished, Finished.

In this case we need a total of 6 if statements, so we could write something like this:

=IF(B2=0, "Not started", IF(B2<10, "Started", IF(B2<50, "First Half", IF(B2=50, "Halfway through", IF(B2<90, "Second half", IF(B2<100, "Almost finished", "Finished"))))))

Excel allows a max of 7 nested if statements. If we wanted to expand our list of possible statuses, we could add only one more condition and one more status. But fortunately we can add more using a different function.

How to use IFS() for more than 7 conditions in Excel

The IFS() function was introduced in Excel 2016, and it allows up to 127 conditions. The syntax is IFS(logical_test1, value_if_true1, [logical_test2, value_if_true2] ... [logical_test127, value_if_true127]).

The logical test expressions are evaluated consequentially. When the first one that returns TRUE is found, the corresponding value_if_true is given as output.

The previous expression that we wrote with nested if statements can be written like this:

=IFS(B2=0, "Not started", B2<10, "Started", B2<50, "First Half"B2=50, "Halfway through", B2<90, "Second half", B2<100, "Almost finished", B2=100, "Finished")

Conclusion

When you need to set conditionally, you’ll often use IF(). You can nest multiple IF() statements to have complex logic chains.

But if you need to use more than 7 nested IF() statements, then you can use IFS() instead.



Learn to code for free. freeCodeCamp’s open source curriculum has helped more than 40,000 people get jobs as developers. Get started

Like this post? Please share to your friends:
  • Многозначные числа в excel
  • Многое ко многим excel 2016
  • Много цифр анализ больших данных с помощью excel
  • Много цифр анализ больших данных при помощи excel скачать полную версию
  • Много цифр анализ больших данных при помощи excel 2016