Excel nested IF statement - multiple conditions in a single formula

The tutorial explains how to use multiple IF in Excel and provides a couple of nested If formula examples for most common tasks.

If someone asks you what Excel function you use most often, what would your answer be? In most cases, it's the Excel IF function. A regular If formula that tests a single condition is very straightforward and easy to write. But what if your data requires more elaborate logical tests with multiple conditions? In this case, you can include several IF functions in one formula, and these multiple If statements are called Excel Nested IF. The biggest advantage of the nested If statement is that it allows you to check more than one condition and return different values depending on the results of those checks, all in a single formula.

Microsoft Excel has limits to the levels of nested IFs. In Excel 2003 and lower, up to 7 levels were allowed. In Excel 2007 and higher, you can nest up to 64 IF functions in one formula.

Further on in this tutorial, you will find a couple of Excel nested If examples along with a detailed explanation of their syntax and logic.

Example 1. Classic nested IF formula

Here's a typical example of Excel If with multiple conditions. Supposing you have a list of students in column A and their exam scores in column B, and you want to classify the scores with the following conditions:

  • Excellent: Over 249
  • Good: between 249 and 200, inclusive
  • Satisfactory: between 199 and 150, inclusive
  • Poor: Under 150

And now, let's write a nested IF function based on the above criteria. It's considered a good practice to begin with the most important condition and keep your functions as simple as possible. Our Excel nested IF formula goes as follows:

=IF(B2>249, "Excellent", IF(B2>=200, "Good", IF(B2>150, "Satisfactory", "Poor")))

And works exactly as it should:
Classic nested IF formula

Understanding Excel nested IF logic

I've heard some people say that Excel multiple If is driving them crazy :) Try looking at it at a different angle:
Nested If formula logic

What the formula actually tells Excel to do is to evaluate the logical_test of the first IF function and, if the condition is met, return the value supplied in the value_if_true argument. If the condition of the 1st If function is not met, then test the 2nd If statement, and so on.

IF(check if B2>=249, if true - return "Excellent", or else
IF(check if B2>=200, if true - return "Good", or else
IF(check if B2>150, if true - return "Satisfactory", if false -
return
"Poor")))

If you need a nested IF formula with wildcard characters (partial match), check out this example: If cell contains, then return different values.

Example 2. Multiple If with arithmetic calculations

Here's another typical task: the unit price varies depending on the specified quantity, and your goal is to write a formula that calculates the total price for any amount of items input in a specific cell. In other words, your formula needs to check multiple conditions and perform different calculations depending on what amount range the specified quantity falls in:

Unit Quantity Price per unit
1 to 10 $20
11 to 19 $18
20 to 49 $16
50 to 100 $13
Over 101 $12

This task can also be accomplished by using multiple IF functions. The logic is the same as in the above example, the only difference is that you multiply the specified quantity by the value returned by nested IFs (i.e. the corresponding price per unit).

Assuming the user enters the quantity in cell B8, the formula is as follows:

=B8*IF(B8>=101, 12, IF(B8>=50, 13, IF(B8>=20, 16, IF( B8>=11, 18, IF(B8>=1, 20, "")))))

And the result will look something similar to this:
Nested IF formula to perform different calculations on numbers within a certain range

As you understand, this example demonstrates only the general approach, and you can easily customize this nested If function depending on your particular task.

For example, instead of "hard-coding" the prices in the formula, you can reference the cells containing those values (cells B2 to B6). This will enable your users to edit the source data without having to update the formula:

=B8*IF(B8>=101,B6, IF(B8>=50, B5, IF(B8>=20, B4, IF( B8>=11, B3, IF(B8>=1, B2, "")))))
An improved formula with multiple IF functions

Or, you may want to include an additional IF function(s) that fixes an upper, lower or both bounds of the amount range. When the quantity is outside the range, the formula will display an "out of the range" message. For example:

=IF(OR(B8>200,B8<1), "Qty. out of range", B8*IF(B8>=101,12, IF(B8>=50, 13, IF(B8>=20, 16, IF( B8>=11, 18, IF(B8>=1, 20, ""))))))
Nested IF's formula with fixed bounds

The nested IF formulas described above work in all versions of Excel. In Excel 365 and Excel 2021, you can also use the IFS function for the same purpose.

Advanced Excel users that are familiar with array formulas, can use this formula that basically does the same thing as the nested IF function discussed above. Though the array formula is far more difficult to comprehend, let along to write, it has one indisputable advantage - you specify the range of cells containing your conditions rather than referencing each condition individually. This makes the formula more flexible, and if your users happen to change any of the existing conditions or add a new one, you will only have to update a single range reference in the formula.

Excel nested IF - tips and tricks

As you have just seen, there is no rocket science in using multiple IF in Excel. The following tips will help you improve your nested IF formulas and prevent common mistakes.

Nested IF limits

In Excel 2007 - Excel 365, you can nest up to 64 IF functions. In older versions of Excel 2003 and lower, up to 7 nested IF functions can be used. However, the fact that you can nest a lot of IFs in one formula doesn't mean you should. Please keep in mind that each additional level makes your formula more difficult to understand and troubleshoot. If your formula has too many nested levels, you may want to optimize it by using one of these alternatives.

The order of nested IF functions matters

The Excel nested IF function evaluates the logical tests in the order they appear in the formula, and as soon as one of the conditions evaluates to TRUE, the subsequent conditions are not tested. In other words, the formula stops after the first TRUE result.

Let's see how it works in practice. With B2 equal to 274, the nested IF formula below evaluates the first logical test (B2>249), and returns "Excellent" because this logical test is TRUE:

=IF(B2>249, "Excellent", IF(B2>=200, "Good", IF(B2>150, "Satisfactory", "Poor")))

Now, let's reverse the order of IF functions:

=IF(B2>150, "Satisfactory", IF(B2>200, "Good", IF(B2>249, "Excellent", "Poor")))

The formula tests the first condition, and because 274 is greater than 150, the result of this logical test is also TRUE. Consequently, the formula returns "Satisfactory" without testing other conditions.

You see, changing the order of IF functions changes the result:
The order of nested IF functions matters

Evaluate the formula logic

To watch the logical flow of your nested IF formula step-by-step, use the Evaluate Formula feature located on the Formula tab, in the Formula Auditing group. The underlined expression is the part currently under evaluation, and clicking the Evaluate button will show you all the steps in the evaluation process.

For example, the evaluation of the first logical test of the nested IF formula shown in the screenshot below will go as follows: B2>249; 274>249; TRUE; Excellent.
Watch the logical flow of your nested IF formula by using the Evaluate Formula feature.

Balance the parenthesis of nested IF functions

One of the main challenges with nested IFs in Excel is matching parenthesis pairs. If the parentheses do not match, your formula won't work. Luckily, Microsoft Excel provides a couple of features that can help you to balance the parentheses when editing a formula:

  • If you have more than one set of parentheses, the parenthesis pairs are shaded in different colors so that the opening parenthesis matches the closing one.
  • When you close a parenthesis, Excel briefly highlights the matching pair. The same bolding, or "flickering", effect is produced when you move through the formula by using the arrow keys.

Balance the parenthesis of nested IF functions

For more information, please see Match parenthesis pairs in Excel formulas.

Treat text and numbers differently

When building logical tests of your nested IF formulas, remember that text and numbers should be treated differently - always enclose text values in double quotes, but never put quotes around numbers:

Right: =IF(B2>249, "Excellent",…)

Wrong: =IF(B2>"249", "Excellent",…)

The logical test of the second formula will return FALSE even if the value in B2 is greater than 249. Why? Because 249 is a number and "249" is a numeric string, which are two different things.

Add spaces or line breaks to make nested IFs easier to read

When building a formula with multiple nested IF levels, you can make the formula's logic clearer by separating different IF functions with spaces or line breaks. Excel doesn't care about extra spacing in a formula, so you may not worry about mangling it.

To move a certain part of the formula to the next line, just click where you want to insert a line break, and press Alt + Enter. Then, expand the formula bar as much as needed and you will see that your nested IF formula has become much easier to understand.
Add line breaks to improve the readability of nested IFs.

Alternatives to nested IF in Excel

To get around the limit of seven nested IF functions in Excel 2003 and older versions and to make your formulas more compact and fast, consider using the following alternatives to nested Excel IF functions.

  1. To test multiple conditions and return different values based on the results of those tests, you can use the CHOOSE function instead of nested IFs.
  2. Build a reference table and a use VLOOKUP with approximate match as shown in this example: VLOOKUP instead of nested IF in Excel.
  3. Use IF with logical functions OR / AND, as demonstrated in the these examples.
  4. Use an array formula like shown in this example.
  5. Combine multiple IF statements by using the CONCATENATE function or the concatenate operator (&). A formula example can be found here.
  6. For experienced Excel users, the best alternative to using multiple nested IF functions might be creating a custom worksheet function using VBA.

This is how you use an If formula in Excel with multiple conditions. I thank you for reading and hope to see you on our blog next week.

Practice workbook for download

Nested If Excel statements (.xlsx file)

649 comments

  1. Been working at this for 3 days and my Brain is starting to hurt. I have these formulas and need to get it into 1 line formula. Each single line works but I can't get them to play nice together.

    Appreciate the help to make this work

    =if(and(A3="D",E3>2000),E3*0.25,"500")
    or
    =if(and(A3="U",E3>1200),E3*0.25,"300")
    or
    =if(and(A3="N",E3>800),E3*0.25,"200")

    • Hello!
      Your formulas contradict each other. For example, if A3 = "" and E3 = 0, then the conditions of all formulas will return FALSE. What value do you want to write in the cell - 500, 300 or 200? Therefore, you cannot combine your formulas. Change the conditions.

  2. Hi Guys,

    Am trying to create an if formula but keep getting errors.

    I am looking at four years data and want to compare individual or collective year results to a rating
    Year 1 = 33%
    Year = 60%
    Year 3 =20%
    Year 5 = 1%
    I want to create a formula which says that if the average of year1 to Year 4 is >=60% but =60%,=60%,<=90%),"meet requirements", "not met requirements").

    Any suggestion is appreciated.

    Thanks

    • Should say if Year 1 to 4 is >=60% but <=90%

    • Hello!
      Describe the background and conditions more precisely. Which means -
      Year = 60% ??
      average of year1 to Year 4 is >=60% but =60%,=60%,<=90%),"meet requirements", "not met requirements") -??

  3. Can anyone guess why my formula below get error

    =IF(J2>=750000, I2+(J2/2), IF(J2>=250000, I2+(J2/3), IF(J2>=100000, I2+(J2/4), IF(J2>=50000), I2+(J2/5))))

    Thanks Guys

    • Hello!
      Please try the following formula:

      =IF(J2>=750000,I2+(J2/2),IF(J2>=250000,I2+(J2/3), IF(J2>=100000,I2+(J2/4),IF(J2>=50000,I2+(J2/5),""))))

      I hope it’ll be helpful.

      • Got formula parse error.. Can i send you Mr Alexander, my screenshot excel, so you can help me analyze it.. thanks a lot mr. alex

        • Hello!
          This formula

          =IF(J2>=750000,I2+(J2/2),IF(J2>=250000,I2+(J2/3), IF(J2>=100000,I2+(J2/4),IF(J2>=50000,I2+(J2/5),""))))

          works for me. J2 and I2 must have numbers.
          What error are you getting?

          • yes, my J2 and I2 already numbers but also get #ERROR! sir.. can you help me review my excel?
            thanks mr.alex

  4. I do hope that you guys/gals are all ok in this time of stress.

    I am trying to use IF, And, and also Or in the same formula.

    =IF(AND('Project Information'!H12="EST",B8>0),LOOKUP(B8,EST),"")

    =IF(AND('Project Information'!H12="system sensor",B8>0),LOOKUP(B8,SS),"")

    I know both the above formulas work but I want to be able to use them both in one formula so if the 1st one doesn't work it will go on to the 2nd one and if neither one work it will show a blank cell.

    Is this possible.

    Thank You Very Much

    Walter Culpepper

  5. Good

  6. =IF(F7=1,((100-H7)*E7)/88),IF(F7=2,((100-H7)*G7)/88)

  7. 2 worksheets A and B

    B pulls from A

    A has 4 columns that are used to calculate monthly median in B.

    Formula: =IFERROR(MEDIAN(IF('[FY2020 Volumes.xlsx]Transplants'!$E:$E="Adult", IF('[FY2020 Volumes.xlsx]Transplants'!$K:$K="Kidney", IF('[FY2020 Volumes.xlsx]Transplants'!$U:$U>=DATE(2019,10,1), IF('[FY2020 Volumes.xlsx]Transplants'!$U:$U<=DATE(2019,10,31), '[FY2020 Volumes.xlsx]Transplants'!$Y:$Y))))), "N/A")

    This pull from Oct 2019 to Sept 2020 calculates the monthly median just fine.

    When i change the dates to 2020,10,1 and 2020,10,31 all i get is zero from Oct 2020 onwards.

    Any help is appreciated.

    thanks

    • Forgot to mention, that column Y is the numbers from whihc the monthly median is calculated.

  8. I am trying to use the following IF formula to return a date and time in D3 when I scan a value into C3:
    =IF(C3"",IF(D3"",D3,NOW()),""). However, it is not a static date/time, it is dynamic, so every time I scan in column C it replaces the last value in column D with the current value as well. I hope this makes sense.

  9. hi i have printing press and 3 machines GTO, SOLNA, HELDELBERG each machine has different capacity of handling paper GTO printing size is 12-18 inches, Solna Size is 18-25 and Heidelberg is 19-40 inches paper handling capacity

    =IF(AND(J17<=12,K1718,K1718,K17<=40),"HEIDELBERG",IF(AND(K17<=12,J1718,J1718,J17<=40),"HEIDELBERG"))))))

    this formula is working to some extant but not working 100% let me know how can i solve my problem

    • Hello!
      Sorry, it's not quite clear what you are trying to achieve. What result do you want to get? What problem or error occurred? Please describe your problem in more detail. It’ll help me understand it better and find a solution for you.

  10. I have columns "A" and "B". "A" is defined as Currency and "B" is a date and "C" contains "=today()". I am trying to populate "B" with todays date when "A" is entered and only when "A" is entered. I have tried:

    =IF(A1>0,$C$1,"") - which populates 'B1" when the sheet is opened if A1>0...I lose the date A1 was entered

    =IF(AND(A1>0,B1=""),$C$1,"") - which didn't work at all...evaluate said circular reference "if 0 > 0"

    I have tried multiple other attempts, but these seemed the most likely. Not sure what I'm doing wrong. Any help/suggestions would be appreciated.

    • Hello!
      Sorry, I do not fully understand the task. Formula =IF(A1>0,$C$1,””) is correct. What does "I lose the date A1 was entered"? Explain your problem in more detail.

      • Thank you for your response.
        I enter a currency amount ($20.00) in A1 on June 1, 2020. The currency amount appears in A1 and 06/01/2020 appears in B1 (populated by the formula). On June 5, 2020 I open the spreadsheet and A1 contains $20.00, B1 contains 06/05/2020.... I lose the date the currency amount was entered. I would like to capture the date the currency amount is entered, and once captured, do not update it again. My second example where if A1 > 0 and B1 Is blank ("") was my attempt to leave B1 alone if it has already been populated, but I couldn't get that to work.

  11. I want to know how to calculate incentive for employees based on the below slab

    Sale Range Incentive
    0 - 2 lakh 0% ( Minimum level )
    2 - 2.5 Lakh 10%
    2.5 - 3 Lakh 15%
    3 - 3.5 Lakh 20%

    If the total sale is 2.75 lakh we have to give the employee an incentive for the amount of 75,000(2.75 lakh - 2.00 lakh ) . Out of the 75000, 50000 will be under 10% and balance 25000 will fall under 15% category. Can you help me to find a formula to calculate the incentive amount.

  12. If D2 is less than or equal to zero then G2 is equal to C2 plus .05, the rest is the same

  13. If D2 is less than or equal to zero then G2 is equal to C2, or if D2 is greater than zero then G2 is equal to C2

  14. Sorry I made a mistake. if D2 then G2 is equal to C2

  15. I need excel to keep/change values in G2. If D20 then I want it to record the same value that is in C2

    • Hi!
      I’m sorry but your task is not entirely clear to me. What does the condition "If D20" mean? Please describe your problem in more detail.

  16. I am trying to use 2 if statements in 1 cell.

    if H2 = Y THEN I2 WILL = E AND IF H2 = N THEN I2 WILL = F
    How can I write this in a formula. I have tried everything and cant get it to work.

    Thank you

    carissa

    • Hello!
      If I understand your task correctly, the following formula should work for you:

      =IF(H2="Y","E",IF(H2="N","F",""))

      Hope this is what you need.

  17. I have a data set on multiple row;
    A1 40
    A2 80
    A3 60
    A4 30
    Is there any way I can use if condition to see A1:A4 >=40 in one take, rather that each if condition check for individual row?
    Thank you.

  18. IF(Data)>F$1,F$1,(Data))
    Can anyone explain, what comes from it and how?

  19. if debit days 0-31 or security=2 month ,"5%",if security=1 month ,"4","3".and other condition is if debit days 31-62 or security=2 month,"4.5",if security=1 month,'3','1.5'. how can we use if formula

  20. Hi
    I've looked across this page trying to find a solution to my problem i have learnt a lot, tried many examples and with adaptions but keep getting errors.
    I'm querying a cell entry, there would be a possible 10 entries but need to show something different in another cell.
    problem - (if_C1=###,then###,or###,then###)
    So if the data in C1=FCP-1 THEN IN CELL J1 SHOW !F1, BUT if C1=FCP-2 then in J1 show !F2 and so on.
    any help would be appreciated.
    Kind regards,
    G

    • Hello!
      I’m sorry but your task is not entirely clear to me. For me to be able to help you better, please describe your task in more detail. Please specify what you were trying to find, what formula you used and what problem or error occurred. Give an example of the source data and the expected result.
      It’ll help me understand it better and find a solution for you. Thank you.

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 :)