The tutorial shows how to create multiple IF statements in Excel with AND as well as OR logic. Also, you will learn how to use IF together with other Excel functions.
In the first part of our Excel IF tutorial, we looked at how to construct a simple IF statement with one condition for text, numbers, dates, blanks and non-blanks. For powerful data analysis, however, you may often need to evaluate multiple conditions at a time. The below formula examples will show you the most effective ways to do this.
How to use IF function with multiple conditions
In essence, there are two types of the IF formula with multiple criteria based on the AND / OR logic. Consequently, in the logical test of your IF formula, you should use one of these functions:
- AND function - returns TRUE if all the conditions are met; FALSE otherwise.
- OR function - returns TRUE if any single condition is met; FALSE otherwise.
To better illustrate the point, let's investigate some real-life formulas examples.
Excel IF statement with multiple conditions (AND logic)
The generic formula of Excel IF with two or more conditions is this:
Translated into a human language, the formula says: If condition 1 is true AND condition 2 is true, return value_if_true; else return value_if_false.
Suppose you have a table listing the scores of two tests in columns B and C. To pass the final exam, a student must have both scores greater than 50.
For the logical test, you use the following AND statement: AND(B2>50, C2>50)
If both conditions are true, the formula will return "Pass"; if any condition is false - "Fail".
=IF(AND(B2>50, B2>50), "Pass", "Fail")
Easy, isn't it? The screenshot below proves that our Excel IF /AND formula works right:
In a similar manner, you can use the Excel IF function with multiple text conditions.
For instance, to output "Good" if both B2 and C2 are greater than 50, "Bad" otherwise, the formula is:
=IF(AND(B2="pass", C2="pass"), "Good!", "Bad")
Important note! The AND function checks all the conditions, even if the already tested one(s) evaluated to FALSE. Such behavior is a bit unusual since in most of programming languages, subsequent conditions are not tested if any of the previous tests has returned FALSE.
In practice, a seemingly correct IF statement may result in an error because of this specificity. For example, the below formula would return #DIV/0! ("divide by zero" error) if cell A2 is equal to 0:
=IF(AND(A2<>0, (1/A2)>0.5),"Good", "Bad")
The avoid this, you should use a nested IF function:
=IF(A2<>0, IF((1/A2)>0.5, "Good", "Bad"), "Bad")
For more information, please see IF AND formula in Excel.
Excel IF function with multiple conditions (OR logic)
To do one thing if any condition is met, otherwise do something else, use this combination of the IF and OR functions:
The difference from the IF / AND formula discussed above is that Excel returns TRUE if any of the specified conditions is true.
So, if in the previous formula, we use OR instead of AND:
=IF(OR(B2>50, B2>50), "Pass", "Fail")
Then anyone who has more than 50 points in either exam will get "Pass" in column D. With such conditions, our students have a better chance to pass the final exam (Yvette being particularly unlucky failing by just 1 point :)
Tip. In case you are creating a multiple IF statement with text and testing a value in one cell with the OR logic (i.e. a cell can be "this" or "that"), then you can build a more compact formula using an array constant.
For example, to mark a sale as "closed" if cell B2 is either "delivered" or "paid", the formula is:
=IF(OR(B2={"delivered", "paid"}), "Closed", "")
More formula examples can be found in Excel IF OR function.
IF with multiple AND & OR statements
If your task requires evaluating several sets of multiple conditions, you will have to utilize both AND & OR functions at a time.
In our sample table, suppose you have the following criteria for checking the exam results:
- Condition 1: exam1>50 and exam2>50
- Condition 2: exam1>40 and exam2>60
If either of the conditions is met, the final exam is deemed passed.
At first sight, the formula seems a little tricky, but in fact it is not! You just express each of the above conditions as an AND statement and nest them in the OR function (since it's not necessary to meet both conditions, either will suffice):
OR(AND(B2>50, C2>50), AND(B2>40, C2>60)
Then, use the OR function for the logical test of IF and supply the desired value_if_true and value_if_false values. As the result, you get the following IF formula with multiple AND / OR conditions:
=IF(OR(AND(B2>50, C2>50), AND(B2>40, C2>60), "Pass", "Fail")
The screenshot below indicates that we've done the formula right:
Naturally, you are not limited to using only two AND/OR functions in your IF formulas. You can use as many of them as your business logic requires, provided that:
- In Excel 2007 and higher, you have no more than 255 arguments, and the total length of the IF formula does not exceed 8,192 characters.
- In Excel 2003 and lower, there are no more than 30 arguments, and the total length of your IF formula does not exceed 1,024 characters.
Nested IF statement to check multiple logical tests
If you want to evaluate multiple logical tests within a single formula, then you can nest several functions one into another. Such functions are called nested IF functions. They prove particularly useful when you wish to return different values depending on the logical tests' results.
Here's a typical example: suppose you want to qualify the students' achievements as "Good", "Satisfactory" and "Poor" based on the following scores:
- Good: 60 or more (>=60)
- Satisfactory: between 40 and 60 (>40 and <60)
- Poor: 40 or less (<=40)
Before writing a formula, consider the order of functions you are going to nest. Excel will evaluate the logical tests in the order they appear in the formula. Once a condition evaluates to TRUE, the subsequent conditions are not tested, meaning the formula stops after the first TRUE result.
In our case, the functions are arranged from largest to smallest:
=IF(B2>=60, "Good", IF(B2>40, "Satisfactory", "Poor"))
Naturally, you can nest more functions if needed (up to 64 in modern versions).
For more information, please see How to use multiple nested IF statements in Excel.
Excel IF array formula with multiple conditions
Another way to get an Excel IF to test multiple conditions is by using an array formula.
To evaluate conditions with the AND logic, use the asterisk:
To test conditions with the OR logic, use the plus sign:
To complete an array formula correctly, press the Ctrl + Shift + Enter keys together. In Excel 365 and Excel 2021, this also works as a regular formula due to support for dynamic arrays.
For example, to get "Pass" if both B2 and C2 are greater than 50, the formula is:
=IF((B2>50) * (C2>50), "Pass", "Fail")
In my Excel 365, a normal formula works just fine (as you can see in the screenshots above). In Excel 2019 and lower, remember to make it an array formula by using the Ctrl + Shift + Enter shortcut.
To evaluate multiple conditions with the OR logic, the formula is:
=IF((B2>50) + (C2>50), "Pass", "Fail")
Using IF together with other functions
This section explains how to use IF in combination with other Excel functions and what benefits this gives to you.
Example 1. If #N/A error in VLOOKUP
When VLOOKUP or other lookup function cannot find something, it returns a #N/A error. To make your tables look nicer, you can return zero, blank, or specific text if #N/A. For this, use this generic formula:
For example:
If #N/A return 0:
If the lookup value in E1 is not found, the formula returns zero.
=IF(ISNA(VLOOKUP(E1, A2:B10, 2,FALSE )), 0, VLOOKUP(E1, A2:B10, 2, FALSE))
If #N/A return blank:
If the lookup value is not found, the formula returns nothing (an empty string).
=IF(ISNA(VLOOKUP(E1, A2:B10, 2,FALSE )), "", VLOOKUP(E1, A2:B10, 2, FALSE))
If #N/A return certain text:
If the lookup value is not found, the formula returns specific text.
=IF(ISNA(VLOOKUP(E1, A2:B10, 2,FALSE )), "Not found", VLOOKUP(E1, A2:B10, 2, FALSE))
For more formula examples, please see VLOOKUP with IF statement in Excel.
Example 2. IF with SUM, AVERAGE, MIN and MAX functions
To sum cell values based on certain criteria, Excel provides the SUMIF and SUMIFS functions.
In some situations, your business logic may require including the SUM function in the logical test of IF. For example, to return different text labels depending on the sum of the values in B2 and C2, the formula is:
=IF(SUM(B2:C2)>130, "Good", IF(SUM(B2:C2)>110, "Satisfactory", "Poor"))
If the sum is greater than 130, the result is "good"; if greater than 110 – "satisfactory', if 110 or lower – "poor".
In a similar fashion, you can embed the AVERAGE function in the logical test of IF and return different labels based on the average score:
=IF(AVERAGE(B2:C2)>65, "Good", IF(AVERAGE(B2:C2)>55, "Satisfactory", "Poor"))
Assuming the total score is in column D, you can identify the highest and lowest values with the help of the MAX and MIN functions:
=IF(D2=MAX($D$2:$D$10), "Best result", "")
=IF(D2=MAX($D$2:$D$10), "Best result", "")
To have both labels in one column, nest the above functions one into another:
=IF(D2=MAX($D$2:$D$10), "Best result", IF(D2=MIN($D$2:$D$10), "Worst result", ""))
Likewise, you can use IF together with your custom functions. For example, you can combine it with GetCellColor or GetCellFontColor to return different results based on a cell color.
In addition, Excel provides a number of functions to calculate data based on conditions. For detailed formula examples, please check out the following tutorials:
Example 3. IF with ISNUMBER, ISTEXT and ISBLANK
To identify text, numbers and blank cells, Microsoft Excel provides special functions such as ISTEXT, ISNUMBER and ISBLANK. By placing them in the logical tests of three nested IF statements, you can identify all different data types in one go:
=IF(ISTEXT(A2), "Text", IF(ISNUMBER(A2), "Number", IF(ISBLANK(A2), "Blank", "")))
Example 4. IF and CONCATENATE
To output the result of IF and some text into one cell, use the CONCATENATE or CONCAT (in Excel 2016 - 365) and IF functions together. For example:
=CONCATENATE("You performed ", IF(B1>100,"fantastic!", IF(B1>50, "well", "poor")))
=CONCAT("You performed ", IF(B1>100,"fantastic!", IF(B1>50, "well", "poor")))
Looking at the screenshot below, you'll hardly need any explanation of what the formula does:
IF ISERROR / ISNA formula in Excel
The modern versions of Excel have special functions to trap errors and replace them with another calculation or predefined value - IFERROR (in Excel 2007 and later) and IFNA (in Excel 2013 and later). In earlier Excel versions, you can use the IF ISERROR and IF ISNA combinations instead.
The difference is that IFERROR and ISERROR handle all possible Excel errors, including #VALUE!, #N/A, #NAME?, #REF!, #NUM!, #DIV/0!, and #NULL!. While IFNA and ISNA specialize solely in #N/A errors.
For example, to replace the "divide by zero" error (#DIV/0!) with your custom text, you can use the following formula:
=IF(ISERROR(A2/B2), "N/A", A2/B2)
And that's all I have to say about using the IF function in Excel. I thank you for reading and hope to see you on our blog next week!
Practice workbook for download
Excel IF multiple criteria - examples (.xlsx file)
4538 comments
How to calculate through xl formula dragging for 2000 rows
Logic.1 Sum first numeric cell starting from A2 at E i.e for row 1 is A2, row2 B2, row 3 C3 and row 4 B4
Logic.2 Sum from 2nd numeric cell to end
i.e for row 1 B1:D1 for row2 B2:D2 for Row3 C3:D3 and row4 B4:D4
- A B C D E F
1 1000 2000 3000 4000
2 - 500 600 700
3 - - 5000 6000
4 - 9000 7000 8000
I'm trying to embed a MID statement for the answer if true. My forumula isn't working, however: =IF(B2=55,(mid(A2,4,2),B2).
Any ideas?
Hello, Annie!
Please try the following formula:
=IF(B2=55,MID(A2,4,2),B2)
Hi,
if it is in excel workbook in one sheet >95 and in other sheet <95 written there, so how we can take average of that( with sign).
please help me to resolve this issue.
Regards,
Vivek
Hello!
If I understand your task correctly, the following formula should work for you:
=IF(OR (AND(Sheet1!A1<95,Sheet2!A1>95), AND(Sheet1!A1>95,Sheet2!A1<95)), AVERAGE(Sheet1!A1,Sheet2!A1),0)
I hope it’ll be helpful.
Please will you give me the function IF in a cell C3 depending of a value in cell B3 with two values , as follows:
in cell b3 with only two values conditions TRUE, with B3=1 or B3=3, in order that:
-for the TRUE two conditions: if B3=1 to give in cell C3 the value effect 5 , and
if B3=3 to give in cell C3 the value effect 10
-for the FALSE condition, if B3 has different value of 1 or 3, to give in cell C3 the value effect 0 (zero).
Thank you.
Hello Dim!
If I understand your task correctly, the following formula should work for you:
=IF(B3=1,5,IF(B3=3,10,0))
If there is anything else I can help you with, please let me know.
Please give me a functio for a cell, as follows:
in cell b3 with only two value conditions b3=1 or b3=3
in order that:
if b3=1 to give in cell c3 the value effect 5
if b3=3 to give in cell c3 the value effect 10
thank you.
Please give me a functio for a cell, as follows:
in cell b3 with only two value conditions b3=1 or b3=3
in order that:
than if b3=1 to give in cell c3 value effect 5
if b3=3 to give in cell c3 value effect 10
thank you.
Hi,
I have some data in which both column and row contains lot of data.
Just want to know that :
1.Column contains data in yellow colour.
2.Want to sum each row with yellow colour .
3.Total of yellow colour data pertains to different different user name.
4.Hence result should be total of yellow colour data in front of respective user name.
Kindly help on this.
Hi Jessica, I am trying to use IF function e.g. If M3:M519 = JNB, then to add an amount that is in the corresponding column cell e.g if M58 = JNB then to add the amount in the corresponding cell e.g. B58 = 195
Does that make sense?
regards Tracy
I need to set formula for the target with criteria as check region is tier I or II then ach.vs target % check , ach.vs ach %, industry growth %, cagr% and stretch the % with 5 or 10 below matrix;
Ach Vs Target Fy 2020 E Ach Vs Ach Fy 2020 E Market share Fy 2020 E YoY Growth Fy 2020 E CAGR Target Growth over PY ach
Tier I Tier II Tier I Tier II Tier I Tier II Tier I Tier II Tier I Tier II Tier I Tier II
65% 65% 0% 0% 2% 2% -15% -15% -10% -10% 5% 5%
80% 80% 10% 10% 8% 8% 1% 1% 1% 1% 10% 10%
90% 90% 30% 30% 10% 10% 5% 5% 5% 5% 15% 15%
100% 100% 50% 50% 15% 15% 10% 10% 10% 10% 20% 25%
125% 125% 90% 90% 18% 18% 20% 20% 20% 20% 25% 30%
Cell A2-A10 has serial numbers
Cell B2-B10 has YES or NO
i want a formula for C2,
IF cell B2 is yes then i need the cell A2's value in cell C2
IF cell B3 is no then i need the cell C3 to be empty
Calculate the following score sheet
NAME GA TWI EWE FRAFRA PERCENT REMARK
a. Use data validate to allow NAME to have not more than 8 characters.
b. When a cell in the name section is selected, the user should be prompted not to type more
than 8 characters in the Name column.
c. Apply conditional formatting to display marks in red color and one decimal place if it is
smaller than 50.
d. Populate your table with the following data:
e. Calculate PERCENT (Note: Percent is the average score for a student) and REMARK.
REMARK is awarded as below:
i. EXCELLENT if any of the marks obtained is more than 90.
ii. V. GOOD if percent is greater than 60
iii. GOOD if percent is greater than 50
iv. FAIL if percent is below 50 or any of the mark is below 60
NAME GA TWI EWE FRAFRA PERCENT REMARK
SATOKA 40 59 24 100
ME LEE 60 67 80 100
EFO LEE 98 1 72 90
LEE SON 88 99 84 60
YOU LEE 76 100 100 90
Please , can someone help me with an appropriate function for question e
We want customers to receive a coupon based on the department they purchased from.
Coupon amounts by department:
Electronics—$25 coupon.
Toys—$20 coupon.
Sports—$15 coupon.
Shoes—$10 coupon.
Every other department—$5 coupon.
Create a column named “Coupon.”
Create a formula that displays the coupon amount for each customer based on department
Hi
Please help me..
My cell values are as follows:-
A1 B1 C1 D1
62 31 0
In cell D1 I need to use a formula that will calculate the value in A1 if C1 =0, but if
C1 >0, then I need to SUM B1+C1
hi.
try this
=IF(C10,C1+B1,0)
Can you please help me to solve this
Fail+Pass+Pass = PASS
Pass+Fail+Pass = PASS
Pass+Pass+Fail = FAIL
Fail+Pass+Pass = FAIL
HOW ??????
Hi - I am trying to work out how to write a formula for the following:
If cellvalue1, "No"
If cellvalue is blank, ""
I have got the yes and no working by using this formula: =IF(E7>1,"No","Yes") but at the moment if there was nothing in cell E7, the cell I have the formula in shows "Yes" and I really want it to be blank (i.e. only say yes or no where there is an actual value in E7). Hope someone can help!
Thanks
kirstie
Hi Kristie, did you find any solution to this? I am in the same condition, looking for that function
please help in the below issue
i have count of 100 people name, and i have to add column B each person against 1 to 10 number.
So it will be like this
Mango 1
Mango 2
Mango 3
Mango 4............
please let me know the formula
its Cntr D i have used but i have large number of data so i can not use the same.
please suggest its urgent
I want multiple of this formula =IF(SUM(COUNTIF(A3,{"*ANCHORAGE*"})),"Alaska",IF(SUM(COUNTIF(A3,{"*Atlanta*"})),"Georgia"))
for several cities, but excel does not let me do more than two IF statements, is there another way to do multiple if statements in one formula?
You can nest as many IF statements as you'd like in Excel.
Just follow the formula:
=IF(Condition,True,IF(Condition,True,IF(...,False)...)
You're just replacing the False part of the IF statement with another IF statement every time. If the first condition isn't true, then it checks for the second, and then the third, etc.
Hello,
I want to calculate an expiry date of a product. The products either have a 5year or 10year working life depending on whether its construction is "rubber" or "synthetic". Over three columns I have MATERIAL, DATED FITTED, EXPIRY DATE. If the material is rubber then I enter =DATE(YEAR(K6)+5,MONTH(K6),DAY(K6)) in the EXPIRY DATE. If the material is synthetic I enter =DATE(YEAR(K6)+10,MONTH(K6),DAY(K6)). Is there a way to make the EXPIRY DATE Column decide automatically how many years to add depending on the contents of the MATERIAL column?
I'm Really struggling with this.
Many thanks.
Tom
hello!
try using if formula for the solution like
=if(A2= "rubber", whole condition with 5 years expiry, if(A2="synthetic", whole condition with 10 years expiry,"")
hi , i m trying to formula for this statment
if A1 greater then 20 twenty then add next row number..
A1 B2
25
32
20
5
I WANT IN B2 NOT MORE THEN 20. ADD NEXT ROW ABOVE 20
hi , i m trying to formula for this statment
if A1 greater then 20 twenty then add next row number..
A1 B2
25
32
20
5
I WANT IN B2 NOT MORE THEN 20. ADD NEXT ROW ABOVE 20