Functions Sample
Functions Sample
If _TRUE an action is performed (in this figure above the action is to write
"Engineer" in cell B2)
If_ FALSE another different action is performed (in this figure above the action is to
write "Worker" in cell B2)
Example 1:
A salesman is paid a commission on sales. He receives 5% if his sales on sales less than 1000
and 10% if his sales on sales 1000 or more. Use IF function to calculate the amount of
commission he receives:
A B
1 Sales Commission
2 1500 =IF(A2<1000;A2*0.05;A2*0.1)
3 2000
4 900
5 1200
6 950
Condition: Sales<1000
True Path Sales*0.05
False Path Sales*0.10
Example 2:
Students are awarded a PASS if they obtain 60 or more marks in a test. Use function IF to enter
the correct result.
A B C
1 Student Marks Result
2 Ahmed 80 =IF(B2<60;”FAIL”;”PASS”)
3 Samir 40
4 Naji 50
5 Hamad 35
Condition: Marks<60
True Path “FAIL” (Text must be enclosed within double quotes)
False Path “PASS” (Text again enclosed within double quotes)
The Nested IF
Nested IF - More Than Two Outcomes
We use nested if when we have more than two outcomes. As an example we will look back on
example 2 above. If I need to grade the students marks as
Less than 60 grade F
60 – 69 grade D
70 – 79 grade C
80 – 89 grade B
90 and better grade A
There are more than 2 outcomes which means I have to test (using IF function) for grade A, B,
C, D, and F
So I simply apply If function as follow
IF (Marks >= 90, "A", IF (Marks>=80, "B", IF (Marks>=70,"C", IF (Marks>=60,"D","F"))))
Note Fourth IF test only the last two out comes (no needs for extra test)
Rule 2 Use the function arguments dialog (you access that by chosen fx then choose logical -
from category then choose IF)
A B C D E
1 Name District Sales Emp. Yrs Job Level
2 Linda East 20000 2
3 Joe West 42302 9
4 Bill East 53001 3
5 Mary South 12000 12
6 Mark South 2050 6
7 John North 9000 0
8 Ted East 40000 4
Cost/Car
5400
6600
7200
10500
VLOOKUP Functions
If the number of outcomes in the Nested IF is large (Ex: 20 outcomes or more) the statement
would become too complex. VLOOKUP function is used instead, where data are put in a table
and we search the table vertically.
Syntax
VLOOKUP(lookup_value,table_array,col_index_num,range_lookup)
Table_array is the table of information in which data is looked up. Absolute value must be
used for the Table Array in order to copy down the formula
Col_index_num is the column number in table_array from which the matching value must be
returned. A col_index_num of 1 returns the value in the first column in table_array; a
col_index_num of 2 returns the value in the second column in table_array, and so on.
Range_lookup is a logical value that specifies whether you want VLOOKUP to find an exact
match or an approximate match.
Example 2
A B
1 Item Price
2 Shoes =VLOOKUP(A2;$A$7:$B$9;2)
3 Jacket
4 Dress
5
6 Table
7 Jacket 150 Table array
8 Shirts 55 A7:B9
9 Shoes 75
10
Note that we used absolute value for the Table Array in order to copy down the formula in the
Price column. The results for the three inputs will be: Dress is not in the table
Shoes 75
Jacket 150
Dress #N/A
Exercise 1 Vlookup
g. Insert a row between row 9 and 10. Type in your name as the salesperson in this
new row. Enter 92000 for the total sales and 50000 for base salary. Copy the
appropriate formulas into Commission, Total Salary and Salesperson's
Evaluation.
Compound IF
COMPOUND STATEMENT
The AND and OR functions can be used if there is more than one condition to be applied
onto the IF function.
AND Connector (function):
This Compound statement can be used in IF statement when we need to test more than
one condition. EX. IF(AND(logical_test1, logical_test2), value_if_true, value_if_false)
OR Connector (Function):
Condition 1 OR Condition 2 Out Come
T T T
T F T
F T T
F F F
OR(logical_test1, logical_test2) – each logical test will produce a T(True) or a
F(false) the out come of OR connector will be according to OR table above.
EX. IF(OR(logical_test1, logical_test2), value_if_true, value_if_false)
Exercise 1 (Compound IF functions) – AND
1. Prepare the CALC workbook as below. Save as YourName_2.xls
Retirement Schedule
The problem:
A person is categorized under 50-60 if his/her age is more than 55 and less and
equal to 60.
Display the result as Yes in C4 if he/she is within the category and display No if
he/she is not under the category.
The problem
1. A person is given
10% commission if
His age > 35 or Years worked >=15
5% commission if
His Age > 30 or years worked > 5
Otherwise his commission is Zero