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. HELP ABOUT THIS CONDITION
    I WANT SOLVE THIS CONDITION WITH IF IN ONE CELL

    CONDITION
    1.10000---TO---24999----20%
    2.25000-----------------20%
    3.25001---TO---49999----25%
    4.50000------------------0
    5.50001---TO---99999----30%
    6.100000----------------0
    7.100001 TO ABOVE-------30%

    PLEASE REPLY MY ?

    • Hello,

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

      =IFS(A1>100000,"30%",A1=100000,"0",A1>50000,"30%",A1=50000,"0",A1>25000,"25%",A1=25000,"20%",A1>=10000,"20%",A1<10000,"")

      Hope this will help you!

  2. I have a question. I have three separate columns with numbers in each cell. I a fourth column I want to place the lowest number that exist in the prior three columns in the cell. How do I go about doing this? Or is it possible?
    A B C Lowest
    100 150 200 100
    150 50 100 50

    • formula is
      =min(A1:D1)
      example
      A B C D
      50 100 150 200 =MIN(50:200)
      FORMULA =MIN(A1:D1)
      ANSWER 50

  3. HELP ABOUT THIS CONDITION
    I WANT SOLVE THIS CONDITION WITH IF IN ONE CELL

    CONDITION
    1.10000---TO---24999----20%
    2.25000-----------------20%
    3.25001---TO---49999----25%
    4.50000------------------0
    5.50001---TO---99999----30%
    6.100000----------------0
    7.100001 TO ABOVE-------30%

  4. i have two tables. in first table i have to check Regid and second table Same RegID and date . After checking both conditions, i have to get the matching data.

    Ex: I was given a car for rent to different customers in different dates.
    i have customer details in one table and which customer taken vehicle on which date i mentioned in another table.

    Now when i enter customer ID and date i have to get all the details of the customer and that vehicle. can anyone help to write formula for this

    • It will be a sql statement to join two tables based on RegID.
      Select *
      from table1
      inner join table2 on table1.RegID=table2.RegID

  5. Hi
    I think my nested IF case is different and maybe weird ;)

    I have a Pivot table filter including 3 options, means I can select 1 or All or only two product categories to produce revenue report outside of the Pivot table it self. I am using SUMIFS to extract the data from Excel table, and filter using the same Pivot filter.
    All working fine until I select 2 product categories (Not All and Not One), I eliminate the problem when selecting (ALL), but could not do the same when I select 2 product categories, the result was all zero values. here is my function:

    =SUMIFS(SalesData[revenue];SalesData[year];I$4;SalesData[region];$H5;SalesData[Category];IF($I$2="(All)";"*";$I$2))
    the previuos one working fine when filtering for One or clearing the filter, means (All), but not when filtering for two categories ...

    my attempt was nested IF:
    IF($I$2="(All)";"*";IF($I$2="(Multiple Items)";$I$2)

    but it dose not work, any help...

  6. I am working on an assignment and I have been stumped for hours. I don't know what I am doing wrong, and hopefully someone can assist me. Here it is...
    9. Many of the special staff teams require leadership training, which is offered to staff with more than 1 year of service at Camp Bright Firewood. Dean wants to identify the staff members eligible for leadership training in the table.
    In cell M2, enter a formula using a nested IF function and structured references to determine first if a staff member already has completed leadership training, and if not, whether that staff member is eligible for leadership training.
    a. If the value of
    b. the Leadership Training column is equal to the text “Yes”, the formula should return the text Completed. Remember to use a structured reference to the Leadership Training column.
    c. If the value of the Leadership Training column is not equal to yes, the formula should determine if the value in the Service Years column is greater than 1.
    d. The formula should return the text Yes if the staff member’s Service Years value is greater than 1.
    e. The formula should return the text No if the staff member’s Service Years value is not greater than 1.
    HERE IS WHAT I KEEP TRYING TO PUT...
    =if([Leadership Training]="YES","Completed", If([Leadership Training]="no"[Service Years]>1, "Yes","no"))
    I just am not getting it. I've done this problem many different ways and not geting the right response.
    Thanks in advance!!

    • =IF(AND([Leadership Training]="Yes", [Service Years]>1), "Completed", IF([Service Years]>1,"Yes","No"))

  7. Hi I'm Mijanur Rahman,
    I want to help !!

    Actually I, get a G.P.A with four subject mark.

    Formula1: Suppose (Sub1+sub2+sub3)/3 it's Main subject GPA (3.93)
    Formula2: IF Sub4 point is sub4>4.00 then add 0.50 with main subject GPA.

    How to write two formula in one line....???
    Plz Help

    • =if (sub4 > 4.00, (sub1+sub2+sub3)/3 + 0.50, (sub1+sub2+sub3)/3)

  8. What if I have multiple overtime pay rates. For example, I want to calculate the total pay for 64 hours worked with these conditions:
    -30 hours or less= $9.50 per hour
    -More than 30 and less than 51=$12.50 per hour
    -51 or more and less than 61=$15.50 per hour
    -61 or more=$18 per hour

    So for hour 1-30, I get paid 285. For hours 31-50, I get paid 237.50, etc. until I'm up to hour 64. I should have a total of 734 but I'm not sure how I would write the formula

    • If (cell <31,cell*9.85,if (cell<51,285 + ((cell - 30)×12.50), 525.50+((cell - 50)×15.50))).

  9. I have a question
    trying to create a nested a nested formula with 3 arguments
    if A>720, B>16, C"IV" display RUX
    please help

    • Hi Mohamed,

      If you want to display "RUX" when all 3 cells contain the values you specified, then use IF in combination with the AND function, like this:

      =IF(AND(A1>720, B1>16, C1="IV"), "RUX", "")

  10. How would you explain to someone who is unfamiliar with Excel how to read a nested statement that contains 3 different conditions??

    • Hi!

      I will try to explain the logic on an example of the first formula in this tutorial:

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

      Translated into plain English, the formula does the following:

      1st IF: Evaluates the 1st condition (if B2 is greater than 249). If the condition is met (if B2>249), returns "Excellent", otherwise proceeds to the 2nd condition.

      2nd IF: Checks if B2 is greater than or equal to 200. If it is, returns "Good", otherwise proceeds to the 3rd condition.

      3rd IF: Checks if B2 is greater than 150. If it is, returns "Satisfactory", otherwise returns "Poor".

      In other words, the formula reads as follows:

      If B2>249, return "Excellent", otherwise check if B2>=200
      If B2>=200, return "Good", otherwise check if B2>150
      IF B2>150, return ""Satisfactory", otherwise return "Poor"

  11. Thanks. This has been pretty useful. I'm trying to create a formula for a document thats over 7000 cells long. Would this negatively affect the formulae? I keep getting an Value? error.

  12. Carolyn:

    I hope on your end what I am saying comes up correctly because on my computer once I hit send, some of what I've written is cut off.

  13. Hi,
    Articles are quite good and knowledgeable.
    Can yo help me with logical functions
    I have some specific data for input diameter, input thickness output diameter and output thickness. based on these values I have to select the speed and feed for machine, which function I have to use, so that formula can check for given input and out put parameters what speed and feed to be selected?

  14. I have a spreadsheet that I need help with. I have two columns, one is Regular and one is Overtime. I need the Overtime column to calculate for anything over 40 in the regular, but I need the regular column to change to 40.
    example....
    Employee has a total of 47 regular hours in column H, I need for column I which is the Overtime column to show the sum of H-40=I, but then for column H to show 40.
    Is this possible and if so how.
    basically in my mind it's If H is >40 then I would be equal to anything >40 and H = 40
    Am I crazy or can this be done?

    • Carolyn Brown:

      Do you manually put the hours in the regular and overtime columns or are there cell references for each column for each employee that populate automatically in those cells in the given work period?

      I don't remember anything before Excel 2013 so this maybe not work if you use a version older than that. I will also answer this assuming that hours populate automatically with cell references for each employee and cells B through G have the total hours worked each day from Monday to Saturday.

      For the regular hour column you can setup an IF statement.
      =IF(sum(B2:G2)40,sum(B2:G2)-40," ")

      You can also setup a data validation in the regular hours column. You can set it where only numerical values can be entered in that column and the value cannot be greater than 40.

    • Carolyn Brown:

      IF(sum(B2:G2)<=40,sum(B2:G2),40) 40,sum(B2:G2)-40," ") <---Overtime Hours Column (should be greater than 40)

  15. 100,000.00 500,000.00 10% 225 one lac to 5-lac than 10% and plus 225
    500,000.00 1,000,000.00 15% 1225 5-lac to 10-lac than 15% and plus 1125
    1,000,000.00 2,000,000.00 18% 2225
    2,000,000.00 3,000,000.00 20% 3225
    Sr No Name of Annual income
    1 waseem 3,500,000.00 350,225.00
    2 waqas 4,000,000.00 400,225.00
    3 waqar 500,000.00 50,225.00
    4 aslam 1,000,000.00 100,225.00
    5 abid 1,500,000.00 150,225.00
    6 abdullah 2,000,000.00 200,225.00
    7 rehman 2,500,000.00 250,225.00
    8 zar 3,000,000.00 300,225.00
    9 tahir 5,000,000.00 500,225.00
    10 altaf 6,000,000.00 600,225.00
    11 shams 300,000.00 30,225.00
    12 pak 800,000.00 80,225.00
    13 lah 900,000.00 90,225.00
    14 pun 6,500,000.00 650,225.00
    15 aus 9,000,000.00 900,225.00
    16 can 1,200,000.00 120,225.00

    please help me i put this formula but not get success.
    =IF(AND(C6=$B$1,C6,$A$2,C6>=$B$2,C6>$A$3,C6>=$B$3,C6>$A$4,C6>=$B$4),"",(C6*10%)+225)

    thanking you anybody help me.

  16. Hi,
    I need help for complex formula, tried using AND, OR, Search with IF but not able to get the result.
    I have a Report data which I have converted into Table, in Column C under the Header "Assignment Group" there are country listed HRss Brazil uat, HRss Portuguese ant, HRss Spain hat, Hrss Italy amt and HRss BR sat. So I was trying this formula:

    =IF(ISERROR(SEARCH("Portu",[Assignment group])),"True", IF("BR",[Assignment group],"False")) - what I want to do is if the country is Brazil or Portuguese or BR then the formula should return to False and rest should be True.
    Please if you can help me it will be great, I have be trying multiple combination but to no avail it returning to "#Valid"

    Many thanks in Advance
    Rinks

  17. Hi admin, I have a case to count between 2 column where these columns has date format, and each columns has different input,I need to count distance between 2 column with condition where ,ex : A1 to B1 has 4 days distance the result is "Done" Where condition 1 Day = 8 hours , and we have to achieve min 20 Hours to get "done" status.

    Please Help me :(

  18. I am trying to create a formula that evaluates multiple cells in the same row that will determine if any of the cells in that range have a no, then a file is failing. I'm using this: =if(countif(A2:H2,"No"),,"Fail","Pass")

    It works for a smaller range, but not a larger range....

    Is there another way to do this?

  19. I have a formula that looks like this in a spread sheet +AZ3*IF)'YTD ALL'!$R$^'Overtime FY17'!AZ$1,'YTD ALL'!$R$6, 'YTD ALL'!$D$6))

    What does this mean? I understand that the "YTD ALL' is another sheet being referenced but I can't figure what it is pulling.

    Apparently the person whose position was more well versed on Excel than I am.

    Thank you in advance

    • Hi Kristi, It is pulling things that are from YTD ALL tab and whatever comes after up to the comma. Example 'YTD ALL!' is the worksheet. $R$ is column R in that worksheet, $R$6 is a cell in that worksheet ect.

  20. Hello, Ms. Svetlana Cheusheva,

    Your IF condition articles are really helpful and much appreciated, I will be so grateful to you if you please help me out to set up this formula…..

    I have several dates on a sheet in a column (e.g. 18/02/2018, 27/02/2018, 29/03/2018) What I want is deduct 10 days from every date and after deducting 10 days I need to check back for the date on Saturday. For example 18/02/2018 Minus (-) 10 days = 08/02/2018, now I check back for the date on Saturday, that is 03/02/2018. 3rd February 2018 will be my result. And another example for the date 29/03/2018 where the result will be 17/03/2018. Can you please help me to build this formula?

    Thank you in advance.

    • Hi Mr Sarder,

      Try this: ="Date"-10-(WEEKDAY("Date"-10))

      In the "Date" you can sellect a cell, eg. A2.

      • Mr Alex, kindly help me in excel color formula.

        i wanna ... clom a = 12
        colm b = 6
        colm c= if colm A is greater then or equale to colm b ..then show red colr in ful cell otherwise white.

        siaz ali

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