Excel IF statement with multiple conditions

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:

IF(AND(condition1, condition2, …), value_if_true, value_if_false)

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: Excel IF statement with multiple AND conditions

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") Excel IF function with multiple text conditions

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:

IF(OR(condition1, condition2, …), value_if_true, value_if_false)

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 :) Excel IF function with multiple OR conditions

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: IF with multiple AND & OR statements

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). Nested IF statement in Excel

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:

IF(condition1) * (condition2) * …, value_if_true, value_if_false)

To test conditions with the OR logic, use the plus sign:

IF(condition1) + (condition2) + …, value_if_true, value_if_false)

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") IF array formula with multiple AND conditions

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") IF array formula with multiple OR conditions

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:

IF(ISNA(VLOOKUP(…)), value_if_na, VLOOKUP(…))

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)) If #N/A error in VLOOKUP

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". Using the IF function with SUM

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", "")) Using IF together with the MIN and MAX functions

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:

  • COUNTIF - count cells that meet a condition
  • COUNTIFS - count cells with multiple criteria
  • SUMIF - conditionally sum cells
  • SUMIFS - sum cells with multiple criteria

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", ""))) IF with ISNUMBER, ISTEXT and ISBLANK

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: Using IF and CONCATENATE

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) Using IF together with ISERROR

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

  1. If there is two dates in a1 and b1
    C1 is 0 to 3 months
    D1 is 3 to 6 months
    E1 is 6 to 12 months
    F1 is 0 to 1 year
    Please suggest formula

  2. Hi
    what is the formula if my condition is
    A=1 ,B=2 the output should be c=1.
    If A=2,B=3 the output should be c=1
    the output should change only if the A= multiples of 1 & B = Multiples of 2 otherwise it will be a least matching.

  3. Identify tickets that do or don't meet the defined service resolution target.

    LOW TICKETS Resolved within 336 hours (10 Days)
    MEDIUM TICKETS Resolved within 168 hours (5 Days)
    HIGH TICKETS Resolved within 4 hours
    CRITICAL TICKETS Resolved within 4 hours

    =IF ((H2=LOW, F<336, "YES", "NO"))
    ((H2=MEDIUM, F<168, "YES", "NO"))
    ((H2=HIGH, F<4, "YES", "NO"))
    ((H2=CRITICAL, F<4, "YES", "NO"))

    I need help in creating one formula that reviews text within cell H2, and then uses the hours the ticket was opened located within F2 and compare it to the given formula based on the ticket priority.

  4. Hello

    I would like to understand how I can create the following formula within excel;
    Column A - Has 3 different values (action 1, action 2, and action 3)
    Column B - Arrival Time
    Column C - Departure Time
    Column D - I need to find the difference in departure time (column C) & arrival time (Column B) of Action 1 (as recorded in column A). However all other times will comeback as 0 (or null figure) as I do not want this to be seen in future analysis

    (Column E) - I need to find the difference in departure time (column C) & arrival time (Column B) of Action 2 (as recorded in column A). However all other times will comeback as 0 (or null figure) as I do not want this to be seen in future analysis

    (Column F) - I need to find the difference in departure time (column C) & arrival time (Column B) of Action 3 (as recorded in column A). However all other times will comeback as 0 (or null figure) as I do not want this to be seen in future analysis

    PLEASE HELP :-)

  5. can i get formula for this

    • If the industry focus is less than 5 and number of solutions is more than 10 – 100%
    • If the industry focus is more than 5 and number of solutions is less than 10 – 80%
    • If the industry focus is more than 5 and number of solutions is more than 10 – 60%
    • If the industry focus is less than 5 and number of solutions is less than 10 – 40%
    • If no data or no information – 20%

  6. =IF(V2=-2,"C","L"),IF(AND,V2>-3,"E")

    THIS DOES NOT WORK. NEED TO SHOW C IF 0,-1,-2,L IF GREATER THAN 0 AND E IF -3

    • =IF(V2>0,"L",IF(AND(V2>=-2,V2<=0),"C",IF(V2<-2,"E","")))

  7. Hi dear
    Can you please let me know how to extract data from a row while comparing multiple sheets' data under some condition in new work sheet?
    For example; I want to make a list of top 10 students from multiple sheets and the entire data against these students must be on a single new sheet.
    Can you guide please!
    Profound regards

  8. Hi I have 2 questions.
    I need to write 2 if arguments
    if a2 - ba = >300 then subtract 300, maximum 600 then subtract (a2-b2)-300 answer maximum 300 if not return 0
    Question 2
    How to embed formulas so excel can be saved and reused without formulas disappearing even if operators mistakenly enter numbers in formula cells
    Thank you very much

  9. Hi, If 1=500 & 2-700. Want to put this formula.
    Can u please help me?

  10. Can someone help me with the following logical statement:
    IF
    "TIMEIN PV"<"TIMEIN DH" AND "TIME IN DH"<"TIMEOUT PV"<"TIMEOUT DH"
    OR
    "TIMEIN DH"<"TIMEIN PV"<"TIMEOUT DH"
    OR
    "TIMEIN DH"<"TIMEIN PV""TIMEOUT DH",
    ALERT,
    0)
    The TIMEIN or TIMEOUT (DH or PV) are formatted in 24:00 hours. I want to create an alert when two schedules are clashing like this:
    PV (Private) (in)xxxxxxxxx(out) (in)xxxxxxxxxxxx(out) (in)xxxxxxxxx(out)
    DH (Dayhab) in ================================================= out

    • Hello Ash,

      Thank you for your comment. As far as I can see, there is a symbol missing in the last part of your formula - "TIMEIN DH"<"TIMEIN PV"”TIMEOUT DH”. Once you add the necessary logical operator (>,<,<>,=) there, it should work. I hope this will help you.

  11. Hello!
    Hopefully a simple one.

    If (A)-(B)=>0(C) - Ongoing(D)
    If (A)-(B)=0(C) - Filled(D)
    If (C) is blank - Not Active

  12. Hi Tried the formula for the time wise but im getting an error for it

    =IF(AND(Al2>07:00:00,Al2=08:00:00,A1=09:00:00,A1=10:00:00,Al2<=11:00:00),"10am-11am",0))))

  13. Basic chart Final chat
    Person Product Quantiy Person Product Quantiy
    A Pen 200 C Rubber Forumula to get quantiy from basic chart
    A Rubber 500
    B Pen 400
    C Pen 800
    C Rubber 200

    • You'll need a few formulas

      =SUMIF(B1:B10,"PEN",C1:C10)
      Formula above sums the values in C1:C10 for the cells in B1:B10 that has "PEN" in it.
      Copy the formula for other products you have.
      =SUMIF(B1:B10,"XXXX",C1:C10)**change the XXXX into the product name**

  14. Basic chart
    Person Product Quantity Person Product Quantity
    ABC Orange 200 GHI Banana Formula to get quantity from basic chart
    ABC Banana 500
    DEF Mango 400
    GHI Banana 800
    GHI Mango 200

  15. Hello,
    I wish to develop a model in excel that provides information on expected loan repayment from clients on a monthly basis so I can easily match with payments received at the end of the month. If the model can also prompt me on the expected repayments for each date that will be mostly appreciated. It will help me reduce my loan delinquency and default.

  16. IF(AND(B43>0,B4320833,B4333332,B4366667,B43166667,B43666667),(((B43-666667)*0.35)+200833.33))

  17. Hello, I need help. I have a range of numbers and looking for If formula which can classify into Over 90 days;
    Over 60 days;
    Over 42 days;
    Below 42 days.
    Please, can you help me with it?

  18. please can you help me the formula to this question
    Currently, customers are responsible for paying the shipping costs. The sales team suggests that customers really dislike paying shipping costs, and that offering “free shipping” instead of the 1% discount would likely increase sales. Create a formula for the “Sales with Free Shipping” column that subtracts the “Shipping Cost” from the “Sales” only if the “Expanded Order Type” is Extra Large, XX Large, or XXX Large. Copy the formula down to all the rows. What would total 2012 sales have been if the company had offered free shipping instead of the 1% discount.

    Order ID Order Date Order Priority Order Quantity Order Type Expanded Order Type Sales Discount Sales with Discount Sales with Free Shipping Ship Mode Shipping Cost
    51648 1/1/2012 Low 45 Large XX Large 2354.8 0.01 2331.252 Regular Air 19.99
    51648 1/1/2012 Low 50 Large XXX Large 187.88 0.01 186.0012 Regular Air 2.97
    29030 1/2/2012 Medium 10 Small Extra Small 192.58 0 192.58 Regular Air 4.1
    54214 1/2/2012 Medium 38 Large Extra Large 7325.63 0.01 7252.3737 Express Air 24.49
    47591 1/2/2012 Critical 27 Medium Medium-Large 279.4 0 279.4 Regular Air 6.91
    43494 1/3/2012 Medium 2 Small Mini 3668.28 0 3668.28 Regular Air 13.99
    10945 1/3/2012 Medium 14 Small Small 1170.025 0 1170.025 Regular Air 8.99
    35811 1/3/2012 Critical 6 Small Extra Small 10.39 0 10.39 Regular Air 0.7
    16164 1/3/2012 Low 26 Medium Medium-Large 2354.15 0 2354.15 Delivery Truck 14
    16164 1/3/2012 Low 26 Medium Medium-Large 69.38 0 69.38 Regular Air 4.28
    50471 1/3/2012 Low 25 Medium Medium 5859.25 0 5859.25 Delivery Truck 28.16
    35811 1/3/2012 Critical 49 Large XXX Large 741.57 0.01 734.1543 Regular Air 1.39
    16164 1/3/2012 Low 22 Medium Medium 3353.54 0 3353.54 Regular Air 19.99
    31555 1/4/2012 Critical 5 Small Mini 500.5 0 500.5 Delivery Truck 28
    55011 1/4/2012 Critical 48 Large XXX Large 452.28 0.01 447.7572 Regular Air 4.82
    7107 1/4/2012 Not Specified 3 Small Mini 172.04 0 172.04 Regular Air 11.1
    44646 1/4/2012 Low 47 Large XXX Large 12723.95 0.01 12596.7105 Regular Air 35
    7107 1/4/2012 Not Specified 3 Small Mini 113.14 0 113.14 Regular Air 5.08

  19. is something wrong with this formula?
    =IF(AND(D3=$A$17, B3=$D$15), $B$17, IF(D3=$A$18, IF(OR(B3=$D$20, G3>$U$18), $B$18,IF(D3=$A$16, IF(AND(MONTH(E3)=$T$18, B3=$D$20), $B$16, $B$19)))))
    instead of showing the right output(percentage), it just says "false", the first 3 if work though.
    Thanks

  20. Help with a formula please:
    If A1<=4 and B1 <=2 then C1 is G
    If A1 =1 and B1 =3 Then C1 is G
    If A1 =5 and B1 =1 Then C1 is A
    If A1 =3,4 and B1 =2 Then C1 is A
    If A1 =2,3 and B1 =3 Then C1 is A
    If A1 =1,2 and B1 =4 Then C1 is A
    If A1 =5 and B1 =2 Then C1 is HA
    If A1 =4 and B1 =3 Then C1 is HA
    If A1 =3 and B1 =4 Then C1 is HA
    If A1 =1,2 and B1 =5 Then C1 is HA
    If A1 =5 and B1 =3 Then C1 is R
    If A1 =4 and B1 =4 Then C1 is R
    If A1 =3 and B1 =5 Then C1 is R
    Many thanks.

    • Hello Adrian,
      First, write down your conditions in different columns:
      – Column G: G1 - 4, G2 - 1, G3 - 5, G4 – 3, etc.
      – Column H: H1 - 2, H2 - 3, H3 – 1, etc.
      – Column I: I1 - "G", I2 - "G", I3 - "A"

      Then paste the array function below in C1:

      =IFERROR(INDEX($I$1:$I$17, MATCH(A1&B1, $G$1:$G$17&$H$1:$H$17, 0)), "")

      Press Ctrl + Shift + Enter for this array function to work and copy this formula down the column. Hope this is exactly what you need. :)

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)