Using functions -2

advertisement
Using Functions in Excel
2
Simple IF
IF function: (Two outcomes)
This is a function that uses logical test to decide on action to be taken
Syntax
IF(logical_test, value_if_true, value_if_false)
1. It is made of three arguments as shown below:-

Logical test: Comparison between two values using logical operators
= Equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
<> Not equal to
B2>100000 as shown in figure above
The out come is either TRUE or FALSE
 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)
Ali B. Izzat
2
Excel – Functions 2
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
Sales
1500
2000
900
1200
950
1
2
3
4
5
6
Condition:
True Path
False Path
B
Commission
=IF(A2<1000;A2*0.05;A2*0.1)
Sales<1000
Sales*0.05
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
Student
Ahmed
Samir
Naji
Hamad
1
2
3
4
5
Condition:
True Path
False Path
Marks<60
“FAIL”
“PASS”
B
C
Marks
Result
80
=IF(B2<60;”FAIL”;”PASS”)
40
50
35
(Text must be enclosed within double quotes)
(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
60 – 69
70 – 79
80 – 89
90 and better
grade F
grade D
grade C
grade B
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"))))
First IF
Ali B. Izzat
Second IF
Third IF
3
Fourth IF
Excel – Functions 2
Where





Marks is cell B2
For First IF- logical test outcome TRUE – Value_if_true becomes A
FALSE – Value_if_false becomes Second IF function
For second IF- logical test outcome TRUE – Value_if_true becomes B
FALSE – Value_if_false becomes Third IF function
For third IF- logical test outcome TRUE – Value_if_true becomes C
FALSE – Value_if_false becomes Fourth IF function
For fourth IF- logical test outcome TRUE – Value_if_true becomes D
FALSE – Value_if_false becomes F
Note Fourth IF test only the last two out comes (no needs for extra test)
Rule 1 in a nested if number of IF functions = Number of outcomes – 1
Rule 2 Use the function arguments dialog (you access that by chosen fx then choose logical -from category
then choose IF)
Rule 3 on the Value_if_false where you need to insert an IF function
 Click in the Value_if_false field first and
 Just choose the IF shown on the left hand side next to formula bar or
 Write in the formula bar before the last closing bracket a "," or ";" depending on what shows up
in the help tip then type IF followed by "(" the dialog will turn into new IF function argument
dialog.
Ali B. Izzat
4
Excel – Functions 2
Exercise 1 (IF function)
1
2
3
4
5
6
7
8
A
Name
Linda
Joe
Bill
Mary
Mark
John
Ted
B
District
East
West
East
South
South
North
East
C
Sales
20000
42302
53001
12000
2050
9000
40000
D
Emp. Yrs
2
9
3
12
6
0
4
E
Job Level
1. Prepare the excel worksheet as the above. Save as YourName_1.xls
2. In cell E2, find out the Job Level for each employee.
If the Emp.Yrs is more than or equal to 5 years, then the Job Level is Senior.
Else if it is less than 5 years, then Job Level is Junior.
Exercise 2 (Nested IF)
Prepare the excel worksheet as shown below
1. Insert the following columns after columns C.
Cost/Car
5400
6600
7200
10500
2. Total cost = QTY* Cost/Car.
3. Tax (column F) is calculate as 0.15 of Total cost
Ali B. Izzat
5
Excel – Functions 2
4. Use Nested if to calculate profit as follow
IF Car Code is 1 then profit is 33% of Total Cost - Tax
Else IF Car Code is 2 then profit is 35% of Total Cost- Tax
Else IF Car Code is 3 then profit is 38% of Total Cost-Tax
Else Profit is 40% of Total Cost- Tax
5. Format Columns E, F, and G as Currency $ with 1000 Comma separator, and one decimal place.
6. Merge and center cells A to G in row 1, add yellow color shade.
7. Add Thick Borders around the merged cells A1:G1.
8. Change the width of columns D to 14.
9. Using the appropriate function: calculate the Totals in cells D8,E8, and G8
10. Calculate in cells E10, E11, and E12.



How many Car types Produced
Highest Total
Lowest Profit
11. Add Thick borders to cells A3:G7.
12. For row 3 fill cells with light blue color.
13. Insert the current date that change automatically in cell A2.
14. Prepare your worksheet for printing with the following requirements.

Orientation: Landscape

Scaling: Fit to one page.

Center page vertically and horizontally.

Add Header: File Name on the left section, your name on the center section and current
date on the right section. Change the font size of your name to 14 and Bold.

Footer: Page number on the center section
15. Rename sheet 1 as Car.
16. Make a copy of sheet car and rename it as final_sheet.
17. Save your work as CarMan.XLS
Ali B. Izzat
6
Excel – Functions 2
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)
Lookup_value is the value to be found in the first column of the table_array.
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 1: Finding Students grade
If Range_lookup was TRUE or omitted, an approximate match is returned. In other words, if an exact match
is not found, the next largest value that is less than lookup_value is returned. For 67 we will get D
Ali B. Izzat
7
Excel – Functions 2
Example 2
If Range_lookup was FALSE (0), VLOOKUP will find an exact match.
Result is
75
55
150
If one value is missing the following will occur
A
1 Item
2 Shoes
3 Jacket
4 Dress
5
6 Table
7 Jacket
8 Shirts
9 Shoes
10
B
Price
=VLOOKUP(A2;$A$7:$B$9;2)
150
55
75
Table array
A7:B9
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
Jacket
Dress
75
150
#N/A
Ali B. Izzat
8
Excel – Functions 2
Exercise 1 Vlookup
Prepare your worksheet sheet 1 as shown below:
Note sheet 2 should have Total Sales < $50,000 in cell A1 and in cell B1 3%
Total Sales ≥ $50,000 in cell A2 and in cell B2 4%
1. Center "ABC" across columns A through F. Change its font size to 16, Bold and font color to Dark
Blue. Change background color of the cell to Yellow.
2. Adjust the column widths when necessary. Perform the following:
a. Use IF function to calculate the commission in cell D4. The commission is based upon the
salesperson's sales.
Note: use value from sheet 2
Note: use cell address not value
If Total Sales less than $50,000, Commission = Total Sales * 3%
If Total Sales more than or equal to $50,000, Commission = Total Sales * 4%.
Copy the formula to D5 through D10.
b. Using the formula below, calculate the Total Salary in column D.
Total Salary = Salary + Commission.
c. Use Nested if to fill in evaluation criteria in Evaluation column according to evaluation table.
d. Use Vlookup to fill in evaluation criteria in Evaluation column according to evaluation table.
Ali B. Izzat
9
Excel – Functions 2
e. Use the appropriate function to calculate the following:
i. Average Salary in cell E14
ii. Highest Total Salary in cell E15
iii. Lowest Total Salary in cell E16
iv. Number of Salesperson in cell E17
v. Number of person whose Total Salary is more than $100,000 in cell E18.
f. Format all numeric values to currency with 0 decimal places. (E.g. 12.0 formatted as $12).
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.
h. Save your file and close the program.
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):
Condition 1
T
T
F
F
AND
Condition 2
T
F
T
F
Condition 1 & 2 is a logical test

Out Come
T
F
F
F
EX. A1>10.
AND(logical_test1, logical_test2) – each logical test will produce a T(True) or a F(false) the out
come of AND connector will be according to AND table above.

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)

Ali B. Izzat
10
Excel – Functions 2
Exercise 1 (Compound IF functions) – AND
1. Prepare the excel workbook as below. Save as YourName_2.xls
Retirement Schedule
Name
Ali
Ahmad
Mariam
Sayed
Aisha
Noor
Age
50
58
60
63
67
70
50-60
61-65
Over 66
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.
Exercise 2 (Compound IF functions) – OR
Prepare the following work sheet
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
2. Calculate in column commission the commission for each person.
Ali B. Izzat
11
Excel – Functions 2
Download