0% found this document useful (0 votes)
21 views

If Condition in Excel

If condition working

Uploaded by

nimishbatra0712
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

If Condition in Excel

If condition working

Uploaded by

nimishbatra0712
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Use of IF, Nested If, IFS

In Excel, the IF function compares a value to an expected value and returns one of
two results, while the IFS function checks if one or more conditions are true and
returns the value that meets the first true condition:
 IF function
Compares a value to an expected value and returns one of two results. The formula
is =IF(test, value-if-true, value-if-false). For example, =IF(C2=”Yes”,1,2) returns 1 if
C2 is "Yes" and 2 if it's not.
 IFS function
Checks if one or more conditions are true and returns the value that meets the first
true condition. The formula is =IFS(logical_test1, value_if_true1, [logical_test2,
value_if_true2], [logical_test3; ...). The IFS function can handle up to 127
conditions.
The main difference between the IF and IFS functions is that IF only has one
conditional with two possible results, while IFS can handle a series of conditions.
Using IF with AND, OR, and NOT functions in Excel
Excel for Microsoft 365 Excel for Microsoft 365 for Mac Excel for the web Excel
2021 More...
In 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 that
condition is True or False.
 =IF(Something is True, then do something, otherwise do something else)
But what if you need to test multiple conditions, where let’s say all conditions need
to be True or False (AND), or only one condition needs to be True or False (OR), or if
you want to check if a condition does NOT meet your criteria? All 3 functions can be
used on their own, but it’s much more common to see them paired with IF functions.
Technical Details
Here are overviews of how to structure AND, OR and NOT functions individually.
When you combine each one of them with an IF statement, they read like this:
 AND – =IF(AND(Something is True, Something else is True), Value if True,
Value if False)
 OR – =IF(OR(Something is True, Something else is True), Value if True, Value if
False)
 NOT – =IF(NOT(Something is True), Value if True, Value if False)
Examples
Following are examples of some common nested IF(AND()), IF(OR()) and IF(NOT())
statements in Excel. The AND and OR functions can support up to 255 individual
conditions, but it’s not good practice to use more than a few because complex,
nested formulas can get very difficult to build, test and maintain. The NOT function
only takes one condition.
Here are the formulas spelled out according to their logic:

Formula Description

=IF(AND(A2>0,B2<100),TRUE, FALSE) IF A2 (25) is greater than 0, AND B2 (75) is less than 10


then return TRUE, otherwise return FALSE. In this case b
conditions are true, so TRUE is returned.

=IF(AND(A3="Red",B3="Green"),TRU If A3 (“Blue”) = “Red”, AND B3 (“Green”) equals “Green


E,FALSE) then return TRUE, otherwise return FALSE. In this case o
the first condition is true, so FALSE is returned.

=IF(OR(A4>0,B4<50),TRUE, FALSE) IF A4 (25) is greater than 0, OR B4 (75) is less than 50,


return TRUE, otherwise return FALSE. In this case, only t
first condition is TRUE, but since OR only requires one
argument to be true the formula returns TRUE.

=IF(OR(A5="Red",B5="Green"),TRUE, IF A5 (“Blue”) equals “Red”, OR B5 (“Green”) equals


FALSE) “Green” then return TRUE, otherwise return FALSE. In th
case, the second argument is True, so the formula retur
TRUE.

=IF(NOT(A6>50),TRUE,FALSE) IF A6 (25) is NOT greater than 50, then return TRUE,


otherwise return FALSE. In this case 25 is not greater th
50, so the formula returns TRUE.

=IF(NOT(A7="Red"),TRUE,FALSE) IF A7 (“Blue”) is NOT equal to “Red”, then return TRUE,


otherwise return FALSE.

Note that all of the examples have a closing parenthesis after their respective
conditions are entered. The remaining True/False arguments are then left as part of
the outer IF statement. You can also substitute Text or Numeric values for the
TRUE/FALSE values to be returned in the examples.
Here are some examples of using AND, OR and NOT to evaluate dates.

Here are the formulas spelled out according to their logic:


Formula Description

=IF(A2>B2,TRUE,FALSE) IF A2 is greater than B2, return TRUE, otherwise return FALSE


03/12/14 is greater than 01/01/14, so the formula returns TR

=IF(AND(A3>B2,A3<C2),TRUE,F IF A3 is greater than B2 AND A3 is less than C2, return TRUE


ALSE) otherwise return FALSE. In this case both arguments are true
the formula returns TRUE.

=IF(OR(A4>B2,A4<B2+60),TRUE IF A4 is greater than B2 OR A4 is less than B2 + 60, return TR


,FALSE) otherwise return FALSE. In this case the first argument is true
but the second is false. Since OR only needs one of the
arguments to be true, the formula returns TRUE. If you use th
Evaluate Formula Wizard from the Formula tab you'll see how
Excel evaluates the formula.

=IF(NOT(A5>B2),TRUE,FALSE) IF A5 is not greater than B2, then return TRUE, otherwise ret
FALSE. In this case, A5 is greater than B2, so the formula retu
FALSE.

Excel: Understand IF, Nested IF, and IFS Functions


In Microsoft Excel, the IF function is simple yet incredibly powerful. In this short
tutorial we will see how to use IF, nested IF, and the new IFS functions.
IF Function
The IF function tests a condition, and then reacts differently depending on whether
the test was true or false. The function itself looks like this:
=IF(test, value-if-true, value-if-false)
Let's try to use it in an example. We have the age of someone, and we want to
display "child" if he is less than 18 years old, or "adult" if he is older. This can be
done with an IF, like this:
 test: AGE<18.
 value-if-true: "child".
 value-if-false: "adult".
 Formula: =IF(AGE<18, "child", "adult").
Just replace AGE by a cell that contains the actual age. In the spreadsheet below
it's C2.

And when we edit the age, the text is updated properly.

That's nice, but we can do even more powerful stuff with nested IF.
Nested IF Functions
Let's continue our previous example, but this time we want to have 3 age groups:
"child" when less than 18, "adult" when less than 80, and "old" otherwise. You
cannot do that with a single IF, 2 are needed:
=IF(AGE<18, "child", IF(AGE<80, "adult", "old"))
The first IF tests whether or not the person is a child, and if not, the second IF will
check if he is an adult or an old person.

This works fine, but if you start nesting more than 2 IF, thing will start to get hard to
read. That's why you might be interested in the IFS function.
IFS Function
IFS is a brand new function that does the same thing as nested IF, but in a clearer
way. It looks like this:
=IFS(test1, value-if-true, test2, value-if-true)
And you can put as many tests as you'd like. Note that this function only works in
Excel 2016 and above. If you try to use IFS in an older version, you'll see the
error #NAME?.
With IFS, our previous example can be re-written like this:
 Before: =IF(AGE<18, "child", IF(AGE<80, "adult", "old"))
 After: =IFS(AGE<18, "child", AGE<80, "adult", AGE>=80, "old")
Both lines do the exact same thing, but the second version is a little easier to read.
That's why I recommend using IFS instead of nested IF.
Logical Tests
Here's the list of all the logical tests you can do in an IF with examples:
 Equal to: A1=A2.
 Higher than: A1>A2.
 Higher or equal than: A1>=A2.
 Less than: A1<A2.
 Less or equal than: A1<=A2.
 Not equal to: A1<>A2.
This is pretty straightforward, except the "not equal to" that combines "higher than"
and "less than" at the same time.
Bonus
Here's a little game that I made, where players have to guess my favorite number.
How would you create that?

Here's the answer below. As you can see, you can make a simple game in excel in
just a line of code :-)
=IFS(C4<42, "too low", C4>42, "too high", C4=42, "you win!")
Conclusion----here's a quick summary of what we covered:
 =IF(test, true, false)
 =IF(test1, true, IF(test2, true, false))
 =IFS(test1, true, test2, true, test3, true)

You might also like