Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

What is an Excel IF Statement?

An Excel IF Statement tests a given condition and returns one value for a TRUE result, and
another value for a FALSE result.

The IF function can perform a logical test and return one value for a TRUE result, and
another for a FALSE result. For example, to "pass" scores above 70:
=IF(A1>70,"Pass","Fail"). More than one condition can be tested by nesting IF functions.
The IF function can be combined with logical functions like AND and OR.

IF Formula
=IF(logical_test, value_if_true, value_if_false)

The formula uses the following arguments:

1. Logical_test (required argument) – It is the condition to be tested and evaluated as


either TRUE or FALSE.
2. Value_if_true (optional argument) – It is the value that will be returned if the
logical_test evaluates to TRUE.
3. Value_if_false (optional argument) – It is the value that will be returned if the
logical_test evaluates to FALSE.

When using the IF function to construct a test, we can use following logical operators:

 = (equal to)
 > (greater than)
 >= (greater than or equal to)
 < (less than)
 <= (less than or equal to)
 <> (not equal to)
Excel IF Function

1. Past-due notices

In this spreadsheet, the customer‘s payment due date is listed in column A, the payment
status is shown in column B, and the customer‘s company name is in column C. The
company accountant enters the date that each payment arrives, which generates this Excel
spreadsheet. The bookkeeper enters a formula in column B that calculates which customers
are more than 30 days past due, then sends late notices accordingly.

A. Enter the formula: =TODAY() in cell A1, which displays as the current date.

B. Enter the formula: =IF(A4-TODAY()>30, ―Past Due‖, ―OK‖) in cell B4.

In English, this formula means: If the date in cell A4 minus today‘s date is greater than 30
days, then enter the words ‗Past Due‘ in cell B4, else/otherwise enter the word ‗OK.‘ Copy
this formula from B4 to B5 through B13.
2. Pass/Fail lifeguard test

The Oregon Lifeguard Certification is a Pass/Fail test that requires participants to meet a
minimum number of qualifications to pass. Scores of less than 70 percent fail, and those
scores greater than that, pass. Column A lists the participants‘ names; column B shows their
scores; and column C displays whether they passed or failed the course. The information in
column C is attained by using an IF statement.

Once the formulas are entered, you can continue to reuse this spreadsheet forever. Just
change the names at the beginning of each quarter, enter the new grades at the end of each
quarter, and Excel calculates the results.

Enter this formula in cell C4: =IF(B4<70,”FAIL”,”PASS”). This means if the score in B4 is
less than 70, then enters the word FAIL in cell B4, else/otherwise enter the word PASS. Copy
this formula from C4 to C5 through C13.
3. Sales & bonus commissions

Wilcox Industries pays its sales staff a 10-percent commission for all sales greater than
$10,000. Sales below this amount do not receive a bonus. The names of the sales staff are
listed in column A. Enter each person‘s total monthly sales in column B. Column C multiples
the total sales by 10 percent, and column D displays the commission amount or the words
‗No Bonus.‘ Now you can add the eligible commissions in column D and find out how much
money was paid out in bonuses for the month of August.

A. Enter this formula in cell C4: =SUM(B4*10%), then copy from C4 to C5 through C13.
This formula calculates 10 percent of each person‘s sales.

B. Enter this formula in cell D4: =IF(B4>10000, C4, ―No bonus‖), then copy from D4 to D5
through D13. This formula copies the percentage from column C for sales greater than
$10,000 or the words ‗No Bonus‘ for sales less than $10,000 into column D.
C. Enter this formula in cell D15: =SUM(D4:D13). This formula sums the total bonus dollars
for the current month.

4. Convert scores to grades with nested IF statements

This example uses a ―nested‖ IF statement to convert the numerical Math scores to letter
grades. The syntax for a nested IF statement is this: IF data is true, then do this; IF data is
true, then do this; IF data is true, then do this; IF data is true, then do this; else/otherwise do
that. You can nest up to seven IF functions.

The student‘s names are listed in column A; numerical scores in Column B; and the letter
grades in column C, which are calculated by a nested IF statement.
A. Enter this formula in cell
C4: =IF(B4>89,‖A‖,IF(B4>79,‖B‖,IF(B4>69,‖C‖,IF(B4>59,‖D‖,‖F‖)))) , then copy from C4
to C5 through C13.

Note: Every open, left parenthesis in a formula must have a matching closed, right
parenthesis. If your formula returns an error, count your parentheses.

5. Determine sliding scale sales commissions with nested IF statements

This example uses another nested IF statement to calculate multiple commission percentages
based on a sliding scale, then totals the commissions for the month. The syntax for a nested
IF statement is this: IF data is true, then do this; IF data is true, then do this; IF data is true,
then do this; else/otherwise do that. The names of the sales staff are listed in column A; each
person‘s total monthly sales are in column B; and the commissions are in column C, which
are calculated by a nested IF statement, then totaled at the bottom of that column (in cell
C15).
A. Enter this formula in cell
C4: =IF(B4<5000,B4*7%,IF(B4<8000,B4*10%,IF(B4<10000,B4*12.5%,B4*15%))), then
copy from C4 to C5 through C13.

B. Enter this formula in cell C15: =SUM(C4:C13). This formula sums the total commission
dollars for the current month.

=IF((DAYS(TODAY();F2))>30;C2*0,75;C2)
In this case, the DAYS function is part of the test: The current data is compared with the
specified date (in F2) and the difference in the number of days is displayed. IF checks
whether the count is higher than 30. If this is the case, the ―then_value‖ where you‘ve placed
a mathematical calculation occurs: a discount is given to the original value (in cell F2).
Otherwise the original value is retained.

Of course, you can also include parameters for then and else. The one drawback of the IF
function is that the test only knows two results: TRUE or FALSE. If you want to
differentiate between multiple conditions, though, a new IF function can occur instead of the
―else_value,‖ which then performs another check.

Excel nested IF statement

Here's the classic Excel nested IF formula in a generic form:

IF(condition1, result1, IF(condition2, result2, IF(condition3, result3, result4)))

You can see that each subsequent IF function is embedded into the value_if_false argument
of the previous function. Each IF function is enclosed in its own set of parentheses, but all the
closing parentheses are at the end of the formula.

Our generic nested IF formula evaluates 3 conditions, and returns 4 different results (result 4
is returned if none of the conditions is TRUE). Translated into a human language, this nested
IF statement tells Excel to do the following:

Test condition1, if TRUE - return result1, if FALSE -


test condition2, if TRUE - return result2, if FALSE -
test condition3, if TRUE - return result3, if FALSE -
return result4
As an example, let's find out commissions for a number of sellers based on the amount of
sales they've made:

Commission Sales

3% $1 - $50

5% $51 - $100

7% $101 - $150

10% Over $150

In math, changing the order of addends does not change the sum. In Excel, changing the
order of IF functions changes the result. Why? Because a nested IF formula returns a value
corresponding to the first TRUE condition. Therefore, in your nested IF statements, it's very
important to arrange the conditions in the right direction - high to low or low to high. In our
case, we check the "highest" condition first, then the "second highest", and so on:

=IF(B2>=150, 10%, IF(B2>=101, 7%, IF(B2>=51, 5%, IF(B2>=1, 3%, ""))))

If we arranged the conditions in the reverse order, from bottom up, the results would be all
wrong because our formula would stop after the first logical test for any value greater than 1.
Let's say, we have $100 in sales - it is greater than 1, so the formula would not check other
conditions and return 3% as the result.

As you see, it takes quite a lot of thought to build the logic of a nested IF statement correctly
all the way to the end. And although Microsoft Excel allows nesting up to 64 IF functions in
one formula, it is not something you'd really want to do in your worksheets. So, if you (or
someone else) are staring at your Excel nested IF formula trying to figure out what it actually
does, it's time to reconsider your strategy and probably choose another tool in your arsenal.

For more information, please see Excel nested IF statement.

Nested IF with OR/AND conditions

In case you need to evaluate a few sets of different conditions, you can express those
conditions using OR as well as AND function, nest the functions inside IF statements, and
then nest the IF statements into each other.

Use the IF function in combination with the AND function and the OR function and become an Excel expert.
1. For example, take a look at the IF function in cell D2 below.

Explanation: the AND function returns TRUE if the first score is greater than or equal to 60 and the second score
is greater than or equal to 90, else it returns FALSE. If TRUE, the IF function returns Pass, if FALSE, the IF
function returns Fail.

2. For example, take a look at the IF function in cell D2 below.

Explanation: the OR function returns TRUE if at least one score is greater than or equal to 60, else it returns
FALSE. If TRUE, the IF function returns Pass, if FALSE, the IF function returns Fail.

3. For example, take a look at the IF function in cell D2 below.


Nested IF in Excel with OR statements

By using the OR function you can check two or more different conditions in the logical test
of each IF function and return TRUE if any (at least one) of the OR arguments evaluates to
TRUE. To see how it actually works, please consider the following example.

Supposing, you have two columns of sales, say January sales in column B and February sales
in column C. You wish to check the numbers in both columns and calculate the commission
based on a higher number. In other words, you build a formula with the following logic: if
either Jan or Feb sales are greater than $150, the seller gets 10% commission, if Jan or Feb
sales are greater than $100, the seller gets 7% commission, and so on.

To have it done, write a few OF statements like OR(B2>=150, C2>=150) and nest them into
the logical tests of the IF functions discussed above. As the result, you get this formula:

=IF(OR(B2>=150, C2>=150), 10%, IF(OR(B2>=101, C2>=101),7%, IF(OR(B2>=51,


C2>=51), 5%, IF(OR(B2>=11, C2>=1), 3%, ""))))

And have the commission assigned based on the higher sales amount:
For more formula examples, please see Excel IF OR statement.

Nested IF in Excel with AND statements

If your logical tests include multiple conditions, and all of those conditions should evaluate to
TRUE, express them by using the AND function.

For example, to assign the commissions based on a lower number of sales, take the above
formula and replace OR with AND statements. To put it differently, you tell Excel to return
10% only if Jan and Feb sales are greater than $150, 7% if Jan and Feb sales are greater than
$100, and so on.

=IF(AND(B2>=150, C2>=150), 10%, IF(AND(B2>=101, C2>=101), 7%,


IF(AND(B2>=51, C2>=51), 5%, IF(AND(B2>=11, C2>=1), 3%, ""))))

As the result, our nested IF formula calculates the commission based on the lower number in
columns B and C. If either column is empty, there is no commission at all because none of
the AND conditions is met:

If you'd like to return 0% instead of blank cells, replace an empty string (''") in the last
argument with 0%:

=IF(AND(B2>=150, C2>=150), 10%, IF(AND(B2>=101, C2>=101), 7%,


IF(AND(B2>=51, C2>=51), 5%, IF(AND(B2>=11, C2>=1), 3%, 0%))))
AND and IF Statements

Just like in a regular program, sometimes in order to examine two or three conditions that
depend on one another, you need to use AND logic. The same is true here.

Let‘s define two new event types: Planned, or Unplanned.

For this example, we‘re going to focus on just the Oil Change column. I know that I usually
schedule my oil changes on the 2nd day of every month. Any oil change that isn‘t on the
second day of the month was an unplanned oil change.

To identify these, we need to use AND logic like this:

=IF(AND(DAY(A2)=2,B2="YES"),"Planned","Unplanned")

The results look like this:

This works great, but as you can see there‘s a slight logical flaw. It works for showing when
oil changes occur on expected dates — those turn up as ―Planned‖. But when the Oil Change
column is blank, the output should also be blank. It doesn‘t make sense to return a result in
those cases because no oil change ever took place.
To accomplish this, we‘ll move on to the next advanced IF function lesson: nested IF
statements.

Nested IF Statements

Building upon the last function, you‘ll need to add another IF statement inside the original IF
statement. This should return a blank if the original Oil Change cell is blank.

Here‘s what that statement looks like:

=IF(ISBLANK(B2),"",IF(AND(DAY(A2)=2,B2="YES"),"Planned","Unplanned"))

Now the statement is starting to look a bit complex, but it really isn‘t if you look closely. The
first IF statement checks if the cell in the B column is blank. If it is, then it returns a blank, or
―‖.

If it isn‘t blank, then you insert the same IF statement we used in the section above, into the
False part of the first IF statement. This way, you‘re only checking for and writing results
about the date of the oil change when there was an actual oil change that took place.
Otherwise, the cell is blank.

As you can imagine, this could get terribly complex. So when you‘re nesting IF statements,
always take it one step at a time. Test individual IF statement logic before you start nesting
them together. Because, once you have a few of these nested, troubleshooting them can
become a real nightmare.

OR Statements

Now we‘re going to kick up the logic just a notch. Let‘s say that this time what I want to do is
return ―Yearly Maintenance‖ if an oil change or repair combined with registration or
insurance is done at the same time, but just ―Routine Maintenance‖ if just an oil change was
done. It sounds complicated, but with the right IF statement logic it isn‘t hard at all.

This kind of logic requires the combination of both a nested IF statement and a couple of OR
statements. Here‘s what that statement will look like:

=IF(OR(B2="YES",C2="YES"),IF(OR(D2="YES",E2="YES"),"Yearly
Maintenance","Routine Maintenance"),"")
Here‘s what that the results look like:

It‘s remarkable the kind of complex analysis you can perform just by combining various
logical operators inside of nested IF statements.

Results Based on Value Ranges

It‘s often very useful to convert value ranges into some kind of text result. This could be as
simple as converting a temperature from 0 to 50 degrees F into ―Cold‖, 50 to 80 as ―Warm‖,
and anything over 80 as hot.

Teachers probably have the most need for this logic because of letter scores. In the following
example we‘re going to explore how to convert a numeric value to text based on just such a
range.

Let‘s say a teacher uses the following ranges to determine letter grade:

 90 to 100 is an A
 80 to 90 is a B
 70 to 80 is a C
 60 to 70 is a D
 Under 60 is an F

Here‘s how that kind of multi-nested-IF statement will look:


=IF(B2>89,"A",IF(B2>79,"B",IF(B2>69,"C",IF(B2>59,"D","F"))))

Each nest is the next range in the series. You just need to be very careful to close out the
statement with the right number of parenthesis or the function won‘t work correctly.

Here‘s what the resulting sheet looks like:

As you can see, this allows you to represent any number in the form of a descriptive string. It
will also update automatically if the numeric value on the sheet ever changes.

You might also like