0% found this document useful (0 votes)
20 views

Nested IF Function: - The Nested IF Statement For This Example Is Made Up of 2 IF Functions. IF

This document discusses nested IF functions and the VLOOKUP function in Excel. It provides examples of using nested IF statements and VLOOKUP to determine age categories (child, adolescent, adult) based on a person's age in cells. The VLOOKUP function allows looking up values in a table to avoid lengthy nested IF statements when there are many outcomes. The document also provides an example of using nested IF statements to calculate sales commissions based on sales amounts in cells.

Uploaded by

Danita Cato
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Nested IF Function: - The Nested IF Statement For This Example Is Made Up of 2 IF Functions. IF

This document discusses nested IF functions and the VLOOKUP function in Excel. It provides examples of using nested IF statements and VLOOKUP to determine age categories (child, adolescent, adult) based on a person's age in cells. The VLOOKUP function allows looking up values in a table to avoid lengthy nested IF statements when there are many outcomes. The document also provides an example of using nested IF statements to calculate sales commissions based on sales amounts in cells.

Uploaded by

Danita Cato
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

4/10/2015

Nested IF Function

• The basic IF function will carry out one of 2 choices.


One action is carried out if a specified test is true. The
other action is carried out if the specified test is false.

• A Nested IF function is when a second IF function is


placed inside the first in order to test additional
conditions. The second IF function can again be a
Nested IF, and so on.

Nested IF Function Example 1


• If you want Excel to decide between 3 Given that
- A child is between ages 0 and 12 (including);
choices, you will need to use a nested IF
- An adolescent is between ages 13 – less than
statement with 2 IF functions. 18; and
• If you want Excel to decide between 4 - An adult is from age 18 and over.

choices, you will need to use a nested IF We are required to:


statement with 3 IF functions, and so on. • create a formula which will automatically tell us
if the person is a child, adolescent or adult.
3 4

Example 1 (using Nested IF)


• The nested IF statement for this example is made up
of 2 IF functions.
=IF( , ,
)

• Each IF function is made up of the 3 arguments:


( , , )

• The 3rd argument for the 1st IF function is actually


the 2nd IF function
5 6

1
4/10/2015

Example 1 (using Nested IF) Example 1 (Using Nested IF)


=IF(B2<=12,“Child",IF( , , ))
• This Excel formula evaluates the value in cell B2. If B2<=12, it
displays the word Child, and stops reading the rest of the • As we will see, there is more than one way of
formula. If the value is >12, Excel executes the 2nd IF statement writing the formula.
in the "value-if-false" argument and determines if the value in
B2 is >=18. If so, it returns a value of Adult. Otherwise, it
means that the value is > 12 and <18 (ie., 13 – 17) and it
displays Adolescent.
• We have looked at 3 different ways of writing the
formula. There are more.
• Note that we do not need to test to see if the value in cell B2
is >12 AND <18 in the 2nd IF function. This is not necessary.
We already KNOW the value is >12 or Microsoft Excel would • All these formulas result in the same answers.
not have proceeded to the second IF statement!
7 8

VLOOKUP Function VLOOKUP function (Contd.)


The format of the VLOOKUP function is
• However, nested IF statements can
=VLOOKUP(lookup_value, table_array, col_index_number,
turn out to be very laborious and [range_lookup])

lengthy to write when there are where


lookup_value: The value you want to look up
many outcomes.
table_array: Where the lookup table is located
• You can avoid writing Nested If col_index_num: The column in the lookup table that has the
statements by using the VLOOKUP value you want returned

function.
9 10

VLOOKUP function (Contd.)


VLOOKUP function (Contd.)
[range_lookup]: Do you want an exact match? Are you dealing with
ranges? This is an optional argument as indicated by the [ ]. We can create our Lookup table as follows:
• If we have ranges that need to be checked, as in
There are 2 cases: our current example with the age ranges, we can
• Consecutive ranges: eg., to see if a person’s age falls within a certain create a 2 column lookup table.
range. Use 1 (or omit) the last argument. The table MUST be sorted
in ascending order of the lookup value.
• The 1st column contains the start value of each
• Exact match: eg., to find a person’s name in a list of names. Use 0 as range, and the 2nd column contains the result if
the last argument, if the table is NOT sorted in ascending order of the data falls in that range. So, our 1st column
the lookup value. You can also use 1 (or omit) the last argument if
the table IS in sorted order. If the exact match is not found, the
will contain the ages, and our 2nd column will
result will be #N/A. contain child/adolescent/adult
11 12

2
4/10/2015

Example 1 (using VLOOKUP)


The VLOOKUP function in cell C3 for our example is as
follows:
=VLOOKUP(B3, E2:F4, 2)
where
• B3 contains the cell to be found
• E2:F4 is the address of the lookup table; and
• 2 refers to the 2nd column of the table from where
the result is to be returned
• Note that we have omitted our last argument, since
we want matches between the start values of 2
consecutive ranges
13 14

Example 1 (using VLOOKUP) Example 2


Given that
• How does this formula
• A company has a policy for individual commissions
=VLOOKUP(B3,E2:F4,2) change when it is depending on sales as shown below:
copied down? – Sales < $10,000, Commission 3%
– Sales >=$10,000 and <$15,0000, Commission 5%
– Sales >=$15,000, Commission 8%

We are required to:


• create a formula which will automatically calculate the
commission for each salesperson depending on the
sales.
15 16

Example 2 (using Nested IF)

=IF(B7<10000,3%*B7,
IF(B7<15000,5%*B7,8%*B7))
OR
=IF(B7>=15000,8%*B7,
IF(B7<10000,3%*B7,5%*B7))
17 18

3
4/10/2015

Example 2 (using VLOOKUP) Example 2 (using VLOOKUP)

• Notice that using the VLOOKUP


table will also make it easier for
the company to change the sales
=VLOOKUP(B3,G2:H4,2) ranges and the commissions
without having to change the
formulas.
19 20

Nested IF function Practice Example 3


Given that A5 = 3 and B5 = 6; Calculating your Pass Status
Given that
What is the result of the function • The criteria for graduation status is as follows:
=IF((A5+B5)<=4, 20, IF((A5+B5)>9, 50, 35)) – GPA <2.0, Not Eligible to Graduate
– GPA>=2.0 and <2.7, Pass
– GPA>=2.7 and <3.4, Pass with Credit
What is the result of the function
– GPA >=3.4, Distinction
=IF((A5+B5)>9, 50, IF((A5+B5)>4, 35, 20))
We are required to:
• create a formula which will automatically calculate the
status for each student depending on the GPA.
21 22

Example 3
– GPA <2.0, Not Eligible to Graduate
– GPA>=2.0 and <2.7, Pass
– GPA>=2.7 and <3.4, Pass with Credit
– GPA >=3.4, Distinction
How many IF statements would we need if we
use the Nested IF function to compute the Pass
status?

23 24

4
4/10/2015

Example 3 (using VLOOKUP) Exercise 9

• Body mass index (BMI) is a simple index of


weight-for-height that is commonly used to
classify overweight and obesity in adults.

=VLOOKUP(B3,F2:G5,2)

25 26

BMI BMI Calculation


• The WHO definition is: To calculate BMI:
– A BMI less than 18.5 is Underweight • Weight in pounds (lbs) divided by height in inches
– A BMI greater than or equal to 18.5 and less than 25 is (in) squared and multiplied by a conversion factor of
Normal 703
– a BMI greater than or equal to 25, and less than 30 is Weight (lbs) x 703
Overweight [Height (in)]2
– a BMI greater than or equal to 30, and less than 40 is
• An example of calculating BMI using the BMI
Obesity formula: Weight = 150 lbs, Height = 5'5" (65 inches)
• BMI Calculation:
– A BMI greater than or equal to 40 is Morbidly 150 x 703 = 24.96
Obese (65)2
27 28

Exercise 9 (using VLOOKUP) Exercise 10


• In this exercise, we will be creating a
spreadsheet model to calculate customers’
bills for a supermarket.
=VLOOKUP(B6,BMI,2)
• Set up the spreadsheet as shown
• Set up the Item List as shown in another
sheet.

29 30

5
4/10/2015

Exercise 10 Exercise 10
• Name the range A2:D10 of the Item List as • VAT is to be applied only to those items that are
Items taxable.
• This involves 2 things:
– Getting Excel to decide whether to charge VAT on a
particular item
– If an item is taxable, Excel then needs to calculate the
tax on the item

31 32

Exercise 10 Exercise 10
• We can apply VAT only to those items that are To get the exact match:
taxable by combining the IF function and the
VLOOKUP function • Use VLOOKUP(A4,Items,4,0) if your table
=IF(VLOOKUP(A4,Items,4,0)="Yes",C4*VAT*D4,0) array is NOT sorted
• You can omit the last argument
• Note also that we have named the VAT cell G1 as
VLOOKUP(A4,Items,4) if your table array is
VAT and use this rather than the data value 16%.
This will allow us to easily change the VAT if the sorted
government changes it.
33 34

You might also like