Excel Nested If
Excel Nested If
Did you know we can use a nested IF formula to extend the number of logical
tests and therefore, possible outcomes? Simply put, this is multiple IF’s
nested in the one formula.
Prior to Excel 2007 the limit of IF's you could nest in one formula was 7. Excel
2007 has increased this to an outrageous 64. I say outrageous, because in
most cases if you’re using more than a few nested IF’s in one formula, there’s
most likely a more efficient way to perform your calculation. So don’t get
carried away nesting!
IF Formula
In a previous tutorial we looked at the IF function (singular), which is one of
the most versatile functions in Excel, but on its own you’re limited to only one
of two outcomes. That is, if the answer to the question I am asking is true, do
this, if not, do that.
Nested IF Formula
Now let’s take a look at a more complex problem that a nested IF would solve.
In our spreadsheet below I’d like to enter the commission for each row in
column G. The commission rates are different for each region. I’ve listed the
different rates in columns I and J so it’s easier to follow.....and later we’ll make
the formula more dynamic using this table, but let’s walk before we run.
With the formula the way it is we’d have to manually update the percentages
for each region if we wanted to alter them. And then copy and paste the
revised formula down the column. A better solution would be to link to the
table in columns I & J. Then if we updated the percentages in column J, our
formula in column G would dynamically update.
For example:
You could take it one step further and link the IF statement to the region
names as well, but I’ll let you play around with that when you download the
practice spreadsheet.
Download the Workbook
Enter your email address below to download the sample workbook.
Get Workbook
By submitting your email address you agree that we can email you our Excel newsletter.
You’ll notice that the references to the rates in column J have $ signs prefixing
the column letter and row number. These are absolute references. You can
learn about absolute references in a previous tutorial and discover how they
can improve your productivity in Excel.
I know I said at the beginning that you shouldn’t use more than a few Nested
IF’s, and I’ve broken that rule here for the purpose of my example. In reality I
would use the VLOOKUP in this scenario as it’s a simpler formula for both the
user to interpret later on, and for Excel to compute.
Warning
Too many nested IF's can result in performance issues. In this tutorial you can
learn alternatives to nested IFs.
Excel IF AND OR Functions Explained
OCTOBER 2, 2010 BY MYNDA TREACY 756 COMMENTS
Excel IF AND OR functions on their own aren’t very exciting, but mix them up with the IF
Statement and you’ve got yourself a formula that’s much more powerful.
In this tutorial we’re going to take a look at the basics of the AND and OR functions and then put
them to work with an IF Statement. If you aren’t familiar with IF Statements, click here to read
that tutorial first.
AND Function
The AND function belongs to the logic family of formulas, along with IF, OR and a few
others. It’s useful when you have multiple conditions that must be met.
In Excel language on its own the AND formula reads like this:
=AND(logical1,[logical2]....)
Now to translate into English:
=OR(logical1,[logical2]....)
Now to translate into English:
=OR(is condition 1 true, OR condition 2 true (add more
conditions if you want)
See, I did say they weren’t very exciting, but let’s mix them up with IF and put AND and OR to
work.
IF AND Formula
First let’s set the scene of our challenge for the IF, AND formula:
In our spreadsheet below we want to calculate a bonus to pay the children’s TV personalities
listed. The rules, as devised by my 4 year old son, are:
2) If they earn less than $100k per year they get a 10% bonus (my 4 year old will write them
an IOU, he’s good for it though).
In English first
=IF(Spider Man is Popular, AND he earns <$100k), calculate his
salary x 10%, if not put "Nil" in the cell)
Now in Excel’s language:
=IF(AND(B2="Yes",C2<100),C2x$H$1,"Nil")
You’ll notice that the two conditions are typed in first, and then the outcomes are entered. You
can have more than two conditions; in fact you can have up to 30 by simply separating each
condition with a comma (see warning below about going overboard with this though).
IF OR Formula
Again let’s set the scene of our challenge for the IF, OR formula:
2) If they earn less than $100k per year they get a 10% bonus.
In English first
=IF(Spider Man is Popular, OR he earns <$100k), calculate his
salary x 10%, if not put “Nil” in the cell)
Now in Excel’s language:
=IF(OR(B2="Yes",C2<100),C2x$H$1,"Nil")
Notice how a subtle change from the AND function to the OR function has a significant impact
on the bonus figure.
Just like the AND function, you can have up to 30 OR conditions nested in the one formula,
again just separate each condition with a comma.
You can set your conditions to test for specific text, as I have done in this example
with B2="Yes", just put the text you want to check between inverted comas “ ”.
Alternatively you can test for a number and because the AND and OR functions belong to the
logic family, you can employ different tests other than the less than (<) operator used in the
examples above.
= Equal to
> Greater Than
<= Less than or equal to
>= Greater than or equal to
<> Less than or greater than
Warning: Don’t go overboard with nesting IF, AND, and OR's, as it will be painful to decipher
if you or someone else ever needs to update the formula in months or years to come.
Note: These formulas work in all versions of Excel, however versions pre Excel 2007 are limited
to 7 nested IF’s.