Download presentation
Presentation is loading. Please wait.
1
Nested IF and Complex Condition
2
Nested IF Example: –Rules to determine bonus: JobCode = 1, Bonus=500 JobCode = 2, Bonus = 700 JobCode = 3, Bonus = 1000 –In C2: If(B2=1, 500, If(B2=2, 700, 1000))
3
JobCode= 1 Or <> =1 JobCode=2 Or <> 2 1 2 3
4
Example Electric Company charges customers based on KiloWatt-Hour used. The rules are: –First 100 KH,20 cents per KH –Each of the next 200 KH ( up to 300 KH), 15 cents per KH –All KH over 300, 10 cents per KH
5
What if we have more than 3 conditions Example: Bonus –JobCode = 1, Bonus = 500 –JobCode = 2, Bonus = 600 –JobCode = 3, Bonus = 700 –JobCode = 4, Bonus = 800 –JobCode = 5, Bonus = 1000 –… Other functions: –Table lookup
6
Example State University calculates students tuition based on the following rules: –State residents: Total units taken <=12, tuition = 1200 Total units taken > 12, tuition = 1200 + 200 per additional unit. –Non residents: Total units taken <= 9, tuition = 3000 Total units taken > 9, tuition = 3000 + 500 per additional unit.
7
Resident or Not Units <= 12 or Not Units <= 9 or Not
8
Complex Condition University admission rules: Applicants will be admitted if meet one of the following rules: –1. Income >= 100,000 –2. GPA > 2.5 AND SAT > 900 An applicant’s Income is 150,000, GPA is 2.9 and SAT is 800. Admitted? –Income >= 100,000 OR GPA > 2.5 AND SAT >900 How to evaluate this complex condition?
9
Scholarship: Business students with GPA at least 3.2 and major in Accounting or CIS qualified to apply: –1. GPA >= 3.2 –2. Major in Accounting OR CIS Is a CIS student with GPA = 2.0 qualified? –GPA >= 3.2 AND Major = “Acct” OR Major = “CIS” Is this complex condition correct?
10
NOT Set 1: Young: Age < 30 Set 2: Rich: Income >= 100,000 YoungRich
11
Order of Evaluation 1. ( ) 2. Not 3. AND 4. OR
12
Rules to calculate employee bonus are: –If JobCode = 1 AND Salary < 5000 OR Sex = “F” Bonus = 10% * Salary –Otherwise: Bonus = 8% * Salary
13
Practices 1. Change the rules for bonus to: –If Sex = “F” AND (JobCode = 1 OR JobCode = 2) then bonus = 10% * Salary –Otherwise, bonus = 8% * Salary 2. Change to rules to: –If JobCode = 1 AND Salary < 5000 OR Sex = “F” Bonus = 10% * Salary –Otherwise: Bonus = 8% * Salary Use a complex condition to describe numbers: 2050100
14
Calculating Conditional Counts and Sums COUNTIF(range, criteria) –Range of cells –Criteria: expression that define which cells are to be counted. SUMIF(range, criteria,[sum_range]) –Sum_range: The cells you want to sum. If omit, Excel will sum the values in the range argument.
15
Example 1.How many employees earn more than 5000? COUNTIF(B2:b4,”>5000”) 2. Compute the total salary of employees earning more than 5000. SUMIF(B2:b4,”>5000”) 3. How many employees’ name begin with “P”? COUNTIF(A2:A4,”P*”)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.