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:
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:
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>=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:
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, "")))))
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, ""))))))
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:
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.
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.
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.
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.
- 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.
- Build a reference table and a use VLOOKUP with approximate match as shown in this example: VLOOKUP instead of nested IF in Excel.
- Use IF with logical functions OR / AND, as demonstrated in the these examples.
- Use an array formula like shown in this example.
- Combine multiple IF statements by using the CONCATENATE function or the concatenate operator (&). A formula example can be found here.
- 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)
650 comments
HI...
Need help for..
If some value has decimal number then I need the next round number.
i.e:- 1.2=2 (1.2 should be shown me by rounding up 2)
4.9=5 (4.9 should be shown me by rounding up 5)
Thanks in advance....
Hi,
try using ROUNDUP function:
for example, if A1 contains '1.2':
=ROUNDUP(A1,0)
hi, if statement e value 0.61 same cell tee value 1.58 below mentioned formula false showing =IF(K91="E",IF(L91=25,0.61,IF(K91="T",IF(L91="25",1.58))))
How to add calendar date and time in excel pzl help me
i want time calculate help as iam not able to get exact time
Hi, post cut off. Here is the formula I am trying to fix.
=IF(and(P2>=60,=98,=123,=148,=175,<=198),"Varsity")))))
Thanks!
Hi, came across this great resource and got partly through problem but not all the way. Trying to find a value based on multiple conditions in a chart.
Here is what I have so far.
=IF(and(P2>=60,=98,=123,=148,=175,<=198),"Varsity")))))
Basically looking at a cell value and determining which group if fits in. based on the value input. The input values could be anything between 60 to 200.
Thank-you!
Hi, Tim,
if you want to return 'Varsity' when the number in the cell falls between 60-200, you can try this:
=IF(AND(P2>=60, P2<=200), "Varsity", "")
If not, please send us a sample workbook with your data and the result you expect to get to support@ablebits.com. Also, mention this article and your comment.
I am trying to get actual budget variance percentage but with an if statement. If actual amount is less than budget then do budget amount minus flex amount divided budget amount and if actual amount is greater than budget amount then do flex amount minus budget amount then divided budget amount. hope this makes sense.
thank you.
Hi, Erly,
Assuming thatC1,(B1-C1)/C1,""))
A1 – actual amount, B1 – flex amount, C1 – budget, and you want to see the result in E1, type the next formula into E1:
=IF(A1
Note, that it misses the condition when the actual amount is equal to budget amount, and in this case the function leaves the cell blank.
Hi,
I want formula that can identify a first 3 or 4 numbers and automatically associate them with location. e.g
809 to Scotland
779 to London
If I put a customer order numbers in Column A : It should automatically show their location in column B by identifying 1st 3 numbers
Column A Column B
8095625 Scotland
8096524 Scotland
7796532 London
8096524 Scotland
Conditions with Multiple Cells, is there a way to clean this up a bit. I'm new to Excel and used your concept to create this monstrosity.
=IF(IF(H352=J352,(IF(J352=L352,(IF(L352=N352,"Valid","Invalid")),"Invalid")),"Invalid")="Not In SAP","Invalid","Valid")
The concept is using 4 cells that have returned a specific value and if they have all returned a specific value and are all the same = "Valid", if one cells is different than the rest = "Invalid".
Thank you
I need to write a "what if" statement for a column that has both numbers & text. For example 79953A, 81012B, 85023C
I want the numbers ending with A to read A Crew in a new column, B to read B Crew and C Crew.
Can I do a "what if" statement to figure out how many A's, B's & C's?
Any information you can give me would be greatly appreciated. Thank you.
Hi, Felicia,
you can try the following:
if your data starts in A1, then to return "A/B/C Crew" to B column use the formula below:
=IF(RIGHT(A1,1)="A", "A Crew", IF(RIGHT(A1,1)="B", "B Crew", IF(RIGHT(A1,1)="C", "C Crew", "")))
To count their amount use COUNTIF in column C:
=COUNTIF(B:B,"A Crew")
where B:B is a column with returned values and "A Crew" counts A appearances. To count "B Crew" and "C Crew" copy and change COUNTIF formula respectively.
if formula with 3 conditions
1- Below Rs,15000 - Rs 0/-
2- 15001 TO 19999 - Rs.150/-
3- Rs20000 - Rs.200/-
Hi there! I'm not sure if this is the correct formula for what I need, but I need a formula that will return a number based on text conditions. For example, if cell A1 reads "Y" or "N/A" I would like the formula to return a 0 value in cell B1. If neither of those conditions are true, I would like B1 to return the numerical value of cell C1.
For context, I am using this to calculate how much use tax I owe. If I paid sales tax on an item or the transaction was not subject to sales tax, then I do not owe additional use tax on it. However, if I did not pay sales tax on the item, I now owe use tax on the full amount of the transaction.
Thanks!
Hi Christina,
You can use the following formula for B1:
=IF(OR(A1="Y", A1="N/A"), 0, C1)
hello,
thank you for all of the input on this site. Very helpful. I am trying to analyze a series of cells and determine the average of those cells. There are only (4) cells in total, but they only show a value higher than zero once a full week has been completed.
i.e.
cell b34 week 1 65%
cell b97 week 2 45%
cell b160 week 3 0% (week not completed yet)
cell b223 week 4 0%,(week not completed yet)
this statement will not work due to too many arguments, but this is what i'd like to achieve.
=IF(B97>0,AVERAGE(B34,B97),B34,IF(B160>0,(AVERAGE(B34,B97,B160)),AVERAGE(B34,B97),IF(B223>0,(AVERAGE(B34,B97,B160,B223,B34)),AVERAGE(B34,B97,B160)))))
Anytime it sees a zero value, skip the rest of the weeks and only use the weeks with % already calculated as part of the monthly average. The trouble i'm having is that if I use a nested if statement, it seems to only function when referencing a single cell. does anyone have any suggestions please?
Hi, i have the following task: This sheet lists items of clothing and accessories, whether or not it is on clearance, and whether or not it is on sale. Items with a “Sales Discount” greater than zero are “on sale”. Items that are both on clearance and on sale get a total discount of 50%. Otherwise, the sale discount is the total discount. Have Excel calculate the total discount for each item.
The data provided for this is:
Clearance Sale Discount
yes 25%
yes 10%
no 10%
no 0%
no 0%
yes 15%
no 5%
yes 0%
no 20%
yes 5%
I need a formula that will provide an answer in % in a 3rd column. I believe it should show either 0%, 50% or the percent in the Sale Discount column. The answer has to take into consideration 4 criteria:
1. Clearance "yes", Sale Discount >0%
2. Clearance "yes", Sale Discount =0%
3. Clearance "no", Sale Discount >0%
4. Clearance "no", Sale Discount =0%
I'm struggling with the IF function as i keep getting errors, or not displaying a %. I'm also struggling with criteria #3, how to make the Sale Discount % appear in column 3.
Can you please help me?
solve my this problam IF TIME IS GRATER THEN AND LESS THEN
=IF(D14-B14>TIME(6,0,0),IF(D5>=10000,"120/-250/-",IF(D5>=6600,"96/-200/-",IF(D5>=5000,"84/-180/-",IF(D5>=3000,"72/-160/-",IF(D5>=1300,"60/-130/-",IF(D14-B14=10000,"250",IF(D5>=6600,"200",IF(D5>=5000,"180",IF(D5>=3000,"160",IF(D5>=1300,"130"))))))))))))
=IF(AND(G4="A",G5="Below 75"),C4*1.708%,IF(AND(G4="A",G5="76-150"),C4*1.708%),IF(AND(G4="A",G5="151-350"),C4*1.793%))
This formula showing "Too many Arguments"
Plz help
=IF(AND(G4="A",G5="Below 75"),C4*1.708%,IF(AND(G4="A",G5="76-150"),C4*1.708%),IF(AND(G4="A",G5="151-350"),C4*1.793%))
This formula is not working.Plz help!!
Good morning and congrats on a wonderful site.
I'm currently running a sheet where I need to identify training dates. I have lets say column B which has the dates of training expiry dates for staff members. I want Column C to read Column B and if the date has not passed already then "Yes" to display, if it has already expired, then "No". Unfortunately Column B is reading from another sheet so some of the dates are #N/A. I want the IF formula to return "No" if they have a #N/A value too.
I currently have =IF(B2>TODAY(),"Yes",IF(B2="#N/A","No","No"))
However this does not work, please help!
Dear sir,
i have the formula written already to calculate the contribution of a staff:
=IF(A1<7100,0,IF(A1<30000,A1*5%,1500))
Which A1 is the income.
but first i need to see if the start date of this staff to an end date is = 2 full months, if yes, then calculate the above, if not, then no need to calculate and contribution =0.
how can i add this criteria to the above formula? Thanks!
Dear sir
I have a sheet where i want to count if column J(month = Jan or feb mar .....) column N = g(Green = good y = possible r = bad)add column D( Value in currency)
Please can you help
Thanks