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. hi
    any idea way the ONLINE NOT show

    =IF(H2&J2="APPROVD","APPROVd",IF(AND(H2&J2="NOTAPPROVD","NOTAPPROVD"),"ONTIME","DEILY"))

      • Write a programme to input an alphabet and then check the alphabet vowel or consonant

  2. Hello!

    I am trying to create and If/Then formula for generations. What I am looking for is if a birthdate (1/1/1954) falls into a range of dates (1/1/1946 to 12/31/2964) then it would be labelled a Baby Boomer. I have 5 generations that I need to include. Thank you!

  3. Great information shared here!! Thanks for sharing.

    I need help with the following formula.

    Column I is a title
    Column J is a dollar

    if column I is X title and column J is less than X dollars increase by Y not to exceed Z but if column J is more than X dollars do not increase.

  4. I need to count the value (will be a whole number) in Column "I" IF Column B word is "New" AND Column C word is "Shirt". How would I set this up?

    Thank you!

  5. Hello,

    Trying to create a formula with no success so far. The range of cells, in this case D:32:D35, are assigned either "yes" or "no". If 1-2 of these cells are marked "yes" then L:31 should be assigned value of .5. However, if 3-4 of the range of cells are marked "yes", then L:31 should be assigned value of 1.

    Any advice greatly appreciated.

    Thanks!

  6. Attenace Incentive allowance
    No Of Day Full OT Incentive Amount Per Day
    26 4 40
    26.5 4 60
    27 3 60
    27.5 3 60
    28 60
    29 60
    30 60
    31 60

  7. Can someone please help me with a basic formula. I have 5 product codes each with a $ value, and I have 200 rows of information, each time I enter a product code in 1 cell then I would like the value shown in the next cell without having to do a manual calculation each time. Is this possible and what would the formula be please. Thank you for any assistance you can offer in this regard.

    • Hi!
      The information you provided is not enough to understand your case and give you any advice.
      What value do you want to display in the next cell? Please describe your problem in more detail.

      • How do I send you the spreadsheet and you can see how Im trying to work it.

        • Hi!
          Please describe your task in more detail and send us a small sample workbook with the source data and expected result to support@ablebits.com. Please shorten your tables to 10-20 rows/columns and include the link to your blog comment.
          We'll look into your task and try to help.

  8. I am looking for a formula that will give me a percentage if a certain number falls within a range of numbers.
    Range:
    $200-$299 I get 1%
    $300-$399 I get 2%
    $400-$1000 I get 3%

    Scenario--My total sales are $39,308 and I worked 147 hours this would put me at $267.40 per hour, by the example below I would get 1% of the 39,308 totaling $393.08 commission

  9. I think, it is more simple you face multiple range data, just make a reference table, sort by value asc, then use VLOOKUP (value, table, col_index, [range_lookup]), with [range_lookup]=1.

  10. Hi how can I make this formula shorter? It seems like it doesn't work because its too long but its all the data i need to input. thank you!!

    =IF(H21>2.8,6.60,IF(H21>2.7,7.20,IF(H21>2.6,7.80,IF(H21>2.5,8.40,IF(H21>2.4,9.00, IF(H21>2.3,9.60,IF(H21>2.2,10.20,IF(H21>2.1,10.80,IF(H21>2.0,11.40,IF(H21>1.9,12.00,IF(H21>1.8,12.60,IF(H21>1.7,13.20,IF(H21>1.6,13.80,IF(H21>1.5,14.40,IF(H21>1.4,15.00,IF(H21>1.3,15.60,IF(H21>1.2,16.20,IF(H21>1.1,16.80,IF(H21>1.0,17.40,IF(H21>0.1,18.00))))))))))))))))))))

    • Kindly,remove the commas from the digits

  11. Thank you - this post of yours helped me to learn something new today.

  12. Here is the IF(AND formula that returns the first answer: =IF(AND(C8="PL",D8="1/4",K8="S304L"),11.16). The problem is I cannot connect that in the same cell with: =IF(AND(C9="PL",D9="1/4",K9="A36"),10.21).

  13. I need to check 3 cells and return an answer, then check the same 3 cells with new conditions and return a new answer. This is a spreadsheet for steel estimates. It needs to see "PL" (plate), "1/4" (thickness), and "S304L" (Stainless Steel) and return a weight per Square Foot. It also needs the see "L" (angle), 2x2x1/4 (size), and "A529-50" (Carbon Steel) and return a weight per Linear Foot. It also needs to see a lot of different shapes, sizes, and grades and return a correct weight per unit. Automating this function would save a lot of time looking through steel books!

    Happy Friday!
    Clark

    • Hello!
      I’m sorry but your task is not entirely clear to me. Could you please describe it in more detail? What result do you want to get? Give an example of the source data and the expected result.

  14. I am trying to write a formula such as this:
    =IF((M10="FORD")*AND(M23="F750")*OR(M23="F550"),1,0)
    Basically i want to return a value of 1 if M10 is equal to FORD and M23 is equal to either F550 or F750.

    This formula returns a value of 1 every time even if i have M23 equal to F250

  15. hi could you help me? im having trouble with my formula.

    here are the conditions;
    if 17<=X<=28, then the answer would be 0.85
    but if 28<X=55, the answer should be 0.65

    thank you

    • X is in cell C4.
      i hope i could reach some help :((

  16. HI,

    I need to calculate the IF statement between two numbers having multiple criteria:

    ex: Criteria
    from 20-30 =200
    from 31-40=300
    from 41-50=500

    B2 = 18
    B3= 25
    B4= 39
    B5=41

    With only one criteria I can calculated: =IF(AND( B2>=31,B2<=40),"300","0"), but when it comes to more I am not sure how to do it.

    Thank you.

    • Hello!
      The formula below will do the trick for you:

      =IFERROR(INDEX(B1:B4,MATCH(D1,A1:A4,1)),0)
      A B
      20 200
      31 300
      41 500
      50 500
      D1 --- 18, 25,39 or 41

      I hope my advice will help you solve your task.

  17. Can you please help me. I have been struggling with this nested formula.

    Cell Values:
    C12 - 85, C13 - 87, C14 - 90, C15 - 95
    D12 - 200, D13 - 300, D14 - 500, D15 - 1000
    E3 - 90, E4 - 86, E5 - 98, E6 - 85

    I need to find the corresponding value for E cells from D cells if the number is greater than or equal to numbers in C cells. [how can I come up with a formula for this? - Cell F should be "500" since E3 => C14]

    Formula in Cell F:
    =IF(E3>=C12,D12,IF(E3>=C13,D13,IF(E3>=C14,D14,IF(E3>=C15,D15,"0"))))

    • Hi,
      I’m sorry but your task is not entirely clear to me. Could you please describe it in more detail? What result do you want to get?
      What does "Cell F should be “500” since E3 => C14"??
      Give an example of the expected result.

  18. Good day Sir

    Can you please help me. I have been struggling with this nested formula.
    I just need someone to please explain it to me cause I just can't grasp this.

    I need a formula which helps me with the following:

    1) If Column B & C has no date populated the Cell E should reflect a " "

    2) IF column B has a date populated and no date populated for Column C then Column E must read "Open"

    3) IF column B & C have a date populated then Column E must read "Finalized"

    I need to have these conditions nested in one in Column E

    Here's the formula I'm using, I think I'm on the right track ;

    =IF(AND(ColumnB>1,ColumC>1),"Finalised", "Open")

    Somewhere in this formula I need amend it to display " " in fields where no Date is captured in Column B

    Column A Column B Column C Column E

    Policy number: Task Start: Task End:
    1234567890 22/02/2021 16:11 22/02/2021 16:14:07

    Please help kind Sir

    • Hello!
      Please use the following formula

      =IF(B1&C1="","",IF(AND(B1 < > "",C1=""),"Open","Finalized"))

      After that you can copy this formula down along the column.

  19. I am working with data across multiple sheets. I have a dropdown list in one sheet. I need a formula that will take the data from multiple sheets and return it to cells on the first sheet of the book based on data chosen in the drop down menu. All data is text I have tried if statements but can't seem to make it work. Any help in this matter would be greatly appreciated.

  20. Greetings,
    =IF(L16>=1,B16,IF(L15>=1,B15,IF(L14>=1,B14,"""")))
    This is the general idea of the formula I need but the data spans thousands of rows. In column L is numbers, column B is dates in descending order. The purpose is to display the date from the same row as cell value in Column L =>1. This formula works but I obviously cannot type out that many conditions. Any help will be greatly appreciated.
    V/R
    Erik

      • A B C D E F G H I J K L
        1 1-May-20 FS 1.0 1.0
        2 3-Jun-21 BS 1.0
        3 5-Jul-19 FS 5.0 1.0
        4 3-Nov-21 BS 1.0
        5 2-Feb-21 BS 1.0
        6 3-Feb-21 1.0
        7 4-Feb-21 .7
        I apologize I don't know how to show the gridlines on here but essentially I need to scan column J for the most recent entry greater than 1 & display the date from column A of the same row. The formula would yield, based on the numbers above, 3 Feb 21 as the most recent date column J was >=1. So one result based on multiple conditions I guess. I just don't know how to get it to scan thousands of rows in a column without doing individual IF formulas in descending order. Thank you for the help.

        • I have looked into the Vlookup option. This function will not work due to the fact that multiple cells may have the same data & it is not in descending order. I need to scan for values >=1.0 & display the date in the same row that is closest to today. So if Cell L14=1.5 the date in B14 would be displayed unless cell L36=1.0 in which case the date in B36 should be displayed. Again, if further down L45=1.0 I want the date in B45 displayed. Thank you again!

        • Hello!
          To find the last match of a value in a column, use the formula

          =LOOKUP(2,1/(D2:D8>=1),B2:B8)

          D2:D8 - column in which we are looking for the condition
          B2:B8 - the column from which we show the value

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