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
I have a list of prices. "X" and "NON-X" products (one column). I want the price separately to the "X" Column and "NON-X" Column from that mixed list..
Hello!
You can use the FILTER function to get a part of the list for an individual product.
This should solve your task.
Hi,
I am trying to create a code for trading.
C3 is Australian Dollar
D3 is Euro
bull is up
bear is down
cons is consolidating/sideways
There is 8 different combinations for the answer that can be seen in the function below.
=IF(AND(D3="bull";C3="bear"); "bull";"") IF(AND(D3="bear";C3="bull");"bear";"") IF(AND(D3="bull";C3="bull"); "cons";"") IF(AND(D3="bear";C3="bear"); "cons";"") IF(AND(D3="bull";C3="cons"); "bull";"") IF(AND(D3="bear";C3="cons"); "bear";"") IF(AND(D3="cons";
Here is the full function
=IF(AND(D3="bull";C3="bear"); "bull";"") IF(AND(D3="bear";C3="bull");"bear";"") IF(AND(D3="bull";C3="bull"); "cons";"") IF(AND(D3="bear";C3="bear"); "cons";"") IF(AND(D3="bull";C3="cons"); "bull";"") IF(AND(D3="bear";C3="cons"); "bear";"") IF(AND(D3="cons";C3="bull"); "bear";"") IF(AND(D3="cons";C3="bear"); "bull";"")
Hello!
If I understand the problem correctly, you have many combinations of conditions in two columns. I recommend writing down all possible combinations in a table and using the VLOOKUP function to search for the desired option. Here is a guide with examples: How to Vlookup multiple criteria in Excel.
I hope I answered your question. If something is still unclear, please feel free to ask.
Thank you for the quick response!
I digged into VLOOKUP function and I am not 100% sure how to use it in my instance. I will try to further explain my situation.
Basically I have 8 possible combinations and 3 possible outcomes, but just one right answer.
First word is one currency (Australian Dollar)
Second word is the other currency (Euro)
Answer is what their cross currency should be if conditions are met (EURO / Australian Dollar)
bull + bull = cons
bear + bear = cons
bull + bear = bear
bear + bull = bull
cons + bull = bull
cons + bear = bear
bull + cons = bear
bear + cons = bull
There can only be one right answer for each date.
Hi!
Write your criteria in the G2:H9 range as:
bullbull cons
bearbear cons
bullbear bear
bearbull bull
......
Formula in cell C2:
=VLOOKUP(A2&B2,G2:H9,2,FALSE)
Please use the link I gave you earlier.
I hope I answered your question.
Hi, I have 2 columns of data, both containing either a 0 or a 1.
I need to be able to code the cell in another column to read the data and return a number...
i.e : when it is 0 in both columns, to return a 0.... then 1 , 0 to return a 1... etc.
I have tried this;
=IF((AND(D2=0, E2=0),0), IF(AND(D2=0, E2=1), 1), IF(AND(D2=1, E2=0), 2), 3)
Any assistance would be greatly appreciated.
Hi!
If I understand your task correctly, try the following formula:
=IF(AND(D2=0,E2=0),0,IF(AND(D2=0,E2=1),1,IF(AND(D2=1,E2=0),2,3)))
Thank you so much for your speedy response. This resolved the issue.
So close, yet so far. Bracket, everybody's best friend and worst enemy.
Range Commission %
> 800 16.0%
> 600 to 400 to 299 to < 399 22.0%
< 299 23.0%
I have a large set of values I need to calculate the commission. How do I apply the formula in excel to calculate the commission value? Please advise.
Hi!
Read carefully the following paragraph of the article above - Using multiple IF statements in Excel (nested IF functions). A few comments just below also have an example of an answer to your question.
Hi, I'm trying to create a formula to show the following:
If residency column is "Res" and "Off" = 32068
If residency column is "Res" and "On" = 31846
If residency column is "Nonres" and "Off"= 61564
If residency column is "Nonres" and "On" = 61342
Thanks!
Hi!
Please re-check the article above since it covers your case. I can't offer you a formula because I don't understand how you would write two values in one column (for example, "Res" and "Off")
Hi
I have multiple conditions to fulfill as described below, I am trying to use IF formula but it is not working. Please suggest.
If a customer selects qty between 0-10 then no discount of total price.
If a customer selects qty between 10-20 then 5% discount of total price.
If a customer selects qty between 20-30 then 10% discount of total price.
If a customer selects qty >30 then 15% discount of total price.
Thank you
Hi!
Pay attention to the following paragraph of the article above - Using multiple IF statements in Excel (nested IF functions), it covers your case completely
=IF(A1>30,15,IF(A1>20,10,IF(A1>10,5,0)))
I have problem, I have to values for L21 & L23 and final outcome is CA..
CA= L23*3+L21*2 if value of L23 is greater than 0
Like - L23 = 3 L21 = 2, then CA = 3*3+2*2=13
and if L23 =0 and L21 =3, then CA=0
Pls suggest farmula
Hello!
If I understand your task correctly, try the following formula:
=IF(L23>0,L23*3+L21*2,IF(L21=3,0,""))
You can learn more about nested IF statements in Excel in this article on our blog.
I'm trying a formula where data exixts in one sheet, i need answer in one sheet with below condition, Can you please provide the formula for this
Sheet 1: Answer & Sheet 2 : Existed Data
I'm inputting formula in Answer sheet with below conditions
If G column Data matches with A Column Data of "Existed Data and
If J Column Data matches with B Coumn Data of "Existed Data and
If Xcolumn Data matches with C columnd Data of : "Existed Data then
answer to be appear which is in D column of Existed Data.
Hi!
Please re-check the article above since it covers your task.
If I got you right,
=IF(AND(G1=A1,J1=B1,X1=C1),D1,"")
You may also find this article useful: Excel reference to another sheet or workbook.
I'm getting an error at end as The formula is missing an Opening or Closing Parenthesis.
Hi!
Check if you copied the formula correctly. It works without errors.
can i select entire column instead of cell
=if(AND(Sheet1!A:A=Sheet2!A:A,Sheet1!B:B=Sheet2!B:B,Sheet1!C:C=Sheet2!C:C,=Sheet1!D:D,"")
Hi!
If I understood your task correctly, you want to compare cells in each row. Therefore, use a relative cell reference to each individual cell in the formula. After that, you can copy this formula down along the column.
I also draw your attention to the fact that the use of column references in formulas significantly slows down the speed of Excel calculations.
In a drop down tab there are 4 names, I want Excel to read selected name and some of the data can be written that person sheet in real time or command to copy
I am totally beginner love to learn, I appreciate you had well explained the use of IF AND OR
Thank you
Hameed
Hey! I want excel to perform different calculation depending on the outcome of a fraction, ive tried the following formula but cant get it working, how should i put it instead?
=IF(SUM(I2/Q2)0.30.50.7, "R2*0.5", "R2*0.75", "R2*0.9", "R2*1.0"))
Hi!
I can't guess what conditions you want to check in your formula. Please describe them. However, all the necessary information to write the formula is in the article above.
I have a problem where scoringh is made based on separate conditions being met and i am stumped.
Example: If name = Type 1 and Condition = Y, score 2, otherwise score 1.
The formula below doesn't seem to work properly.
=IF(AND(Y2="Y"),IF(AND(P2="Type 1"),2,1))
Additionally, If neither is it possible to have 0, rather than FALSE?
If anyone is able to answer this for me, i'd be extremely grateful :)
Hello!
If I understand your task correctly, try the following formula:
=IF(AND(Y2="Y",P2="Type 1"),2,1)
Here is the article that may be helpful to you: Excel Nested IF statement: examples, best practices and alternatives.
Thanks for your help, that's great!
hi need this code to correct please help
i have date on M17 given and the are encode MM/DD/YYYY
i want to auto fill the date if 1st quarter or 2nd and so on.....
this is my sample code but the result is always 4th Quarter need help to correct it thank you
=IF(M17>=10/1/2022,"4th Quarter",IF(M17>=7/1/2022,"3rd Quarter",IF(M17>=4/1/2022,"2nd Quarter",IF(M17>=1/1/2022,"1st Quarter"))))
i have date on M17 given and they are encoded on this format MM/DD/YYYY dateshort
Hello!
The expression M17>=10/1/2022 is incorrect. I recommend that you read the instructions - Excel IF formula examples for dates.
To get a date value, in addition to the DATEVALUE function, you can use the DATE function.
This should solve your task.
I will use this ( if(vlookup(a2, sheet1! A:ap, 42,0) ="TN", A2, "") fourmal this condition only sow TN state,
Now I need TN & KA State which fourmal use plz help????
Hi!
I am not sure I fully understand what you mean.
Hello,
I am trying to make eGFR calculator. It needs to differ between men and women and different serum concentrations of creatinine (SCr). Formula reads as follows:
142 x (Scr/A)^B x 0.9938^age x (1.012 if female), where A and B are the following:
Female Male
SCr ≤0.7, A = 0.7 B = -0.241 SCr ≤0.9 A = 0.9 B = -0.302
SCr >0.7 A = 0.7 B = -1.2 SCr >0.9 A = 0.9 B = -1.2
So what I need is to Excel calculate/show value of B in one cell when specific conditions are met. For example patient is female and SCr is 0,55 (it is <0,7) B should be B=-0,241 and etc.
Is it possible to test combinations of two variables (sex and SCr) to calculate three possible outcomes of B (-0,241, for women, -0,302 for men, and -1,2 in cases when SCr is greater than 0,7 for women, 0,9 for men, respectively)?
Looking forward to your answer
Edit of previous comment due to error.
Hello!
Please check out the following article on our blog, it’ll be sure to help you with your task: Excel INDEX MATCH MATCH and other formulas for two-way lookup.
I hope my advice will help you solve your task.
I please need help doing a formula for the following, which should just be one formula :Combine these into 1 formula
if cell A is empty , it must use cell B info , if cell B is empty, it must use cell A info , If both cell A and B has info in it then it must use Cell B info, If no info then it must show a clear cell and not a 0.
Hi!
I hope you have studied the recommendations in the tutorial above. It contains answers to your question. Try the following formula:
=IF(AND(ISBLANK(A1),ISBLANK(B1)),"", IF(ISBLANK(B1),A1,B1))
To not show 0 in an empty cell, use custom number format.
Hi there, I am looking for a formula which will return the following result:
If text in cell A1 matches the text in cell range A1:A100, then show text from cell B1, assuming A1 is Name and B1 is Surname, please help.
Hi!
I’m not sure I got you right since the description you provided is not entirely clear. Your terms and conditions are incorrect. The text in cell A1 will always match the text in range A1:A100 in cell A1.
If you want to find the corresponding surname by name, then use the VLOOKUP function. For example:
=VLOOKUP("Name",A1:B100,2,0)
Hi
=IF(OR(AND(L37="Yes"),OR(M36="Yes",N36="Yes",M37="Yes",N37="Yes")),"Yes","No")
Effectively, the formula should be saying if L37 is Yes, and M37 or N37 is Yes, then give Yes, or if L37 is No, and M36 or N36 is Yes, then give Yes. Everything else, give No.
the above formula is coming back as a Yes where it should say No.
are there any other formalas i can use?
Hello!
If I understand your task correctly, try the following formula:
=IF(AND(L37="Yes",OR(M37="Yes",N37="Yes")),"Yes", IF(AND(L37="No",OR(M36="Yes",N36="Yes")), "Yes","No"))
Please re-check the article above since it covers your task.
I am trying to get a formula for my budget.
I need to calculate Management fees that are calculated at 2% of revenue. There is a minimum charge of $20,000.00 meaning that the least I will be invoiced for management fees is $20,000.00.
So my formula needs to read that if 2% of my revenue is less then $20 000 then the answer is $20 000. If 2% of my revenue is greater than $20 000 then the answer should be 2% of that figure.
Hello!
Here is the article that may be helpful to you: How to use IF function in Excel.
You can use this formula:
=IF(A1*0.02<20000,20000,A1*0.02)
Hi,
Can You help me in this below Case
=IF(F17=0, "F43*1", IF(F17=0.5, "F43*0.5", IF(F17=1, "F43*0")))
Here In "F43*1" - Is also the formula
Explanation,
If F17 = 0, then F43 should multiplies with 1 (F43*1),
Similarly, As follows
If F17 = 0.5, then F43 should multiplies with 0.5 (F43*0.5),
If F17 = 1, then F43 should multiplies with 0 (F43*0),
*F43 is Sum of (F18:F42)
Hi!
In the IF function, as in other functions, quotes should only be used with text values.
Please try the following formula:
=IF(F17=0, F43*1, IF(F17=0.5, F43*0.5, IF(F17=1, F43*0, "")))
Hi can you help me, the other formula is not working
=IF(G1110,G11*24.17, IF(G11>20, G11*26.39, IF(G11>30, G11*28.92, IF(G11>40, G11*32.15)))))
Hello!
I can't test your formula because I don't know what result you want. But your formula was written incorrectly and contained an extra bracket.
=IF(G1110,G11*24.17,IF(G11 > 20,G11*26.39,IF(G11 > 30,G11*28.92,IF(G11 > 40,G11*32.15))))
here's the water rate per cu.m.
0-10 CU.M = 224.02 (MINIMUM RATE)
11-20 CU.M = 24.17 PER CU.M
21-30 CU.M = 26.39 PER CU.M
31-40 CU.M = 28.92 PER CU.M
OVER 40 CU.M = 32.15 PER CU.M
WHAT FORMULA SHOULD I USE, THAT ALL THE CONDITIONS WILL WORK.
THANKS IN ADVANCE
Hi!
Read the following paragraph of the article above carefully - Using multiple IF statements in Excel (nested IF functions), it covers your case completely.
See this comment for the answer to a similar question.
Hi, if in one cell (C25) I have 3 possible options (1, X, 2) then how can I get the values if 1=3, if X=1 and if 2=0? I typed the following formula, but with no luck
=IF(C25=1;3,IF(C25=x;1,IF(C25=2;0)))
Hello!
Don't forget that character values must be enclosed in quotes.
=IF(C25=1,3,IF(C25=2,0,IF(C25="X",1,"")))