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. Hey There,

    I am trying a formula that,
    one cell is having the same details of other selected cell by putting "=" but in the same cell how I include the formula if the selected cell is blank and in that case I can put "NA". Example,

    In cell A1 is having a drop down list of material
    In cell B1 I can put B1=A1, that means what ever the name of material will appear in Cell B1. Now If there is no value in cell A1 then how I include the "NA" in formula of cell B1. So that if there is material name than that will appear on cell B1 but if there is nothing then the Cell B1 will appeared as "NA".
    If you can help me it will be very helpful for me.

  2. I am trying to calculate the following, the formula is in cell E3. Drop downs in cell G3 containing Premier and Elite with associated values of 1.5 for Premier and 1 for Elite. These selected values of 1.5 or 1 are loaded into cell E3 after being selected.

    =IF(G3="Premier",1.5,IF(G3="Elite",1,IF(ISTEXT(I3),E3*0.5))

    Everything works fine except for the Istext function. If any text is found in I3 then I want to apply a division formula to reduce the resulting value in the E3 cell by 50%. The values of E3 should then be .75 for Premier and/or .5 for Elite if text is found in I3. What may I be doing wrong?

  3. Sir I have 3 if condition statements I want join them and want to make single condition kindly help me on this

  4. Try this instead
    =IF((OR((ISNUMBER(SEARCH("SERETIDE",AA2))),(ISNUMBER(SEARCH("SYMBICORT",AA2))),"YES","NO"))

  5. I'm struggling to combine IF function with an OR while incorporating text values with partial match.
    This is what I've gotten so far, but I'm not sure why it doesn't work.

    =IF((OR((ISNUMBER(SEARCH("SERETIDE",AA2))),(ISNUMBER(SEARCH("SYMBICORT",AA2)))),"YES","NO"))

    Thank you for the help.

    • Try this instead
      =IF((OR((ISNUMBER(SEARCH("SERETIDE",AA2))),(ISNUMBER(SEARCH("SYMBICORT",AA2))),"YES","NO"))

  6. 95% to 100% Silver
    100% to 102% Gold
    102% to 105% Diamond
    > 105% Platinum

    in slab calculation range for (95% to 100 % )

    how is work

    • Hello,

      Please try the following formula:

      =IF(A1>105,"Platinum",IF(A1>102,"Diamond",IF(A1>100,"Gold",IF(A1>95,"Silver",""))))

      Hope this will work for you.

  7. 95% to 100% Silver
    100% to 102% Gold
    102% to 105% Diamond
    > 105% Platinum
    in slab calculation is value from to (95 % to 100%)

    how is do

  8. Has anyone attempted the MOS Excel Expert Part 2 if so can anyone help me with the question that ask to divide column D by Column E. Then use a Nested If and Roundup Function to roundup to the nearest integer.

  9. Hi, wondering if anyone could help me.

    I need one cell to equal LL. If the value in another column is equal to 3.90, 4.90, 5.45, 5.95 or 11.40 I need the column next to this value to equal LL. I can do it with one value but not with all the values?

    Thanks,

  10. I am trying to create a formula that will first multiply a weight times a dollar amount then add a value from one of 4 columns where a choice needs to be made and an additional column that will be added regardless. These 'choice' columns are not cumulative they are exclusionary. If one has a value then non of the others will be added to the weight times dollar amount and the additional column.

    In a sentence it looks something like this:

    (weight*.65)+L13 if P13=FALSE)+(M13 if L13=0 and if P13=FALSE)+(N13 if L13=0 and if M13=0 and if P13=FALSE)+O13 (This is the column that is always added) if P13=80 (weight*.65)+O13+P13

    Thank you!

  11. I have this formula =VALUE(IF(B4="high risk", "5", IF(B4="restricted industry", "5", IF(B4="medium risk", "3", IF(B4="low risk", "1"))))) imbedded so it will assign the numerical value once a selection is made from the drop down list next to this field. However, I have new data (a lot of options in the drop down now) and need the above formula to look for a partial match instead of an identical match. For example, instead of high/med/low wording, I know have a list of countries that have attached ratings like "Estonia-Low". And I need that formula to assign the numerical risk rating (5/3/1) based on a partial match for the Low/Medium/High that will be attached to the country name. Thank you so much for your help. I've been reading blog posts all night and can't figure it out.

  12. =IF(((HLOOKUP(Y$1,Patterns!$AS$2:$AW$42,Patterns!$AP33,0))*((Forecasts!$AI$1*Y266)+Forecasts!$AJ$1))<1,1,((HLOOKUP(Y$1,Patterns!$AS$2:$AW$42,Patterns!$AP33,0))*((Forecasts!$AI$1*Y266)+Forecasts!$AJ$1)))

    Can someone help me with this formula? What is it trying to achieve?

  13. Hi, can you have more than one condition to get a same result? I have a range of prices, and essentially if the price is above a certain value, a 0 score, is given. However, I want to also give a 0 score if there is no price, or the price is blank.... =IF(K218.75,"0")))))))))))))
    I want to add that if K2 is a 0 price, or if K2 is blank, my formula must also revert with a 0 value. Thanks for any help

    • Hello,

      If I understand your task correctly, please try the following formula:

      =IF(OR(K2>18.75,K2=0,ISBLANK(K2)),"0")

      Hope this will help.

  14. Hello,

    I have a column of names and another column with a value. I am trying to build out a formula that will capture the the value in the row depending on the name. Something like "IF"Tricia,sumF15".

  15. I am trying to find a way to indicate if there is >10 consecutive duplicate values in a column and if so have a cell marked as yes but if no then have the column show a no. An example can be seen below of what I want it to look like.
    A1 B1
    Y N
    N N
    Y Y
    Y Y
    Y Y
    Y Y
    Y Y
    Y Y
    Y Y
    Y Y
    Y Y
    Y Y
    Y Y
    Y Y
    Y Y
    N N
    N N
    N N
    N N
    N N
    N N
    Y N
    Y N

    Is there a way to get an equation that looks at consecutive duplicate values and flags them if there is higher that a set value?

    • Hello,

      If I understand your task correctly, please try to enter the following formula in cell B1:

      =IFERROR(IF(COUNTIF($A1:$A11,$A1)=11,"Y",IF(AND(OFFSET($B1,-1,0)="Y",OFFSET($A1,-1,0)=$A1),"Y","N")),"N")

      Just select the cell where you've entered the formula and drag the fill handle (a small square at the lower right-hand corner of the selected cell) down.

      Hope this will help.

  16. I really need a summary for 4 conditions but have a problem like this

    if A4C4 or equal D4 then D4
    if A4>D4 or equal E4 then E4
    if A4>F4 then F4

    Help me pls.

    • I really need a summary for 4 conditions but have a problem like this

      if A4C4 or equal D4 then D4
      if A4>D4 or equal E4 then E4
      if A4>F4 then F4

      Help me pls.

      • 01 - if A4C4 or equal D4 then D4
        03 - if A4>D4 or equal E4 then E4
        04 - if A4>F4 then F4

        • Hello,

          If I understand your task correctly, please try the following formula:

          =IF(OR(A4>C4,A4=D4),D4,IF(OR(A4>D4,A4=E4),E4,IF(A4>F4,F4,"")))

          Hope this will help.

  17. Hello,
    I have a report of incoming phone calls. I have the following columns: Start time (time stamp of when the call was received), Call duration (length of the call), and I have calculated a third column of time between calls, but not sure if that is necessary. We have 2 phone reps available to take calls. I am wanting to find out based on the time stamp of the incoming calls, and the duration of the calls if the 2 phone reps can handle the call volume. Im thinking this would be an IF THEN calculation, but i cant figure it out. Are you able to help?

  18. Good Morning,

    Mis,Svetlana Cheusheva!

    Thank you very much for your kind excel work,i appreciate with your every tutorial and helpful for taking a the example thank you very much once again if i need any help i will take your approach.

  19. I have a vehicle report that has the starting mileage at the top of the page in D6, then I have a column for each day of the month, another column with ending daily mileage and the last column is total daily mileage. My supervisor wants to be able to put the ending mileage and it figure how many miles were driven that day. My problem is that some days the vehicle doesn't move so a zero needs to go in the column. My formula for day 1 is =IF(OR(B10=0), "0", (B10-D6)) so now what do I do for day 2-31 if it could be 0 everyday or could be mileage to get it to go back up to the last place mileage was entered to get that days total?

    • Hello,
      For me to understand the problem better, please send me a small sample workbook with your source data and the result you expect to get to support@ablebits.com. Please don't worry if you have confidential information there, we never disclose the data we get from our customers and delete it as soon as the problem is resolved.
      Please also don't forget to include the link to this comment into your email.
      I'll look into your task and try to help.

  20. Hi there...
    i need some help if u can pls..
    i run a car renter service and i want to find which of my car earn how much in a single day
    i got some sheets in a single file these sheets got my daily sales
    i need to make a sheet which sums all the amount from all the sheets which contain same car num
    the sheets are made by driver that this driver drove this car on this date
    hope am able to convey u my issue

    • Raza here again sorry i forgot to give an example for this:
      lets say Sheet 1 got data of driver 1 and sheet 2 got data of driver 2
      lets say driver 1 drove car A on 1st dec and drove car B on 2nd dec
      and driver 2 drove car B on 1st dec and car A on 2nd dec
      i want a sheet which just calculate that how much earning was done on that car on that day wether it b driven by more than 2 drivers

      • Hello,
        For me to understand the problem better, please send me a small sample workbook with your source data and the result you expect to get to support@ablebits.com. Please don't worry if you have confidential information there, we never disclose the data we get from our customers and delete it as soon as the problem is resolved.
        Please also don't forget to include the link to this comment into your email.
        I'll look into your task and try to help.

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