Download presentation
Presentation is loading. Please wait.
Published byElwin Cornelius Lawson Modified over 9 years ago
1
CS105 Fall 20091 CS105 Lab 3 – Excel: The IF Function Announcements MP 1 will be released on Monday 9/14, due Monday 9/28 by 9pm Midterm 1 on Tuesday 9/29 at 7pm Last day to request a conflict for Midterm 1: Thursday 9/24 by 7pm
2
CS105 Fall 20092 Lab Objectives Learn the IF function. Learn to use nested IF. Learn to use Lookup Tables Learn to reference other worksheets in Excel. Learn to create pie chart Go to the course website and download the Excel Worksheet for Lab 3.
3
CS105 Fall 20093 A “real world” Scenario… This spreadsheet contains sales data for a tea manufacturing company which sells 3 different brands of tea. As an executive, you want to find out how much of the revenue comes from each product line, i.e : complete range E3:G26 We’ll use the IF function to do this.
4
CS105 Fall 20094 The IF Function Flowchart Condition True False Result for True Condition Result for False Condition
5
CS105 Fall 20095 How Does IF Work in Excel? Recall from lecture how the formula =IF(condition, result1, result2) works. Excel looks at the condition. If it is true, result1 is returned. If it is false, result2 is returned. The condition must be something that is either true or false; that is, the condition must be BOOLEAN.
6
CS105 Fall 20096 Setting Up Our IF Function Our product names are in column A. If a cell in column A matches cell E2 (Lively Lemon Tea), we want to put its revenue value (column D) in the Sales column for Lively Lemon Tea (column E). Otherwise we want to put 0 in that column.
7
CS105 Fall 20097 Display 0 Product is Lively Lemon Tea True False Display revenue Flowchart for Cell E3 How do we write the IF function? =IF(A3=E2, D3, 0)
8
CS105 Fall 20098 Copying the formula We must modify the relative references to absolute/mixed references before copying Double-click on the fill handle to fill the column for “Lively Lemon Tea.” Use the fill handle to copy the formula to cells F3 and G3. Double-click on the fill handle in F3 and G3 to fill columns F and G. =IF($A3=E$2, $D3, 0)
9
CS105 Fall 20099 Nested IF You can have an IF function inside another IF function Handy if you have more than one condition to test. If “midterm is not this week” then “continue sleeping”, otherwise if “I’m not too sleepy” then “go to class”, otherwise “continue sleeping”
10
CS105 Fall 200910 The Nested IF Flowchart Midterm is on tomorrow Not too sleepy Continue sleeping Go to class True False Continue sleeping
11
CS105 Fall 200911 The Nested IF Flowchart Condition 1 Condition 2 Result for False Condition 1 Result for True Condition 1 and False Condition 2 Result for True Condition 1 and True Condition 2 True False This is not the only way nested IFs can be done. Can you think of some other ways?
12
CS105 Fall 200912 Calculating Eastern Region Sales Suppose we want to compute the total sales for each product in the East region ONLY. If column C contains the value that is “East”, then if the product name (in column A) matches corresponding tea product in H2:J2, display the revenue. Otherwise display 0 Fill in cells in collumn H,I,J.
13
CS105 Fall 200913 The Formula for Cell H3 =IF($C3="East",IF($A3=H$2,$D3,0),0) Double-click on the fill handle to fill the column for “Lively Lemon Tea.” Use the fill handle to copy the formula to cells I3 and J3. Double-click on the fill handle to fill columns I and J.
14
CS105 Fall 200914 AND, OR, and NOT review In lecture we saw AND, OR, NOT condition1 AND condition2 returns TRUE only when Both condition1 and condition2 must be TRUE condition1 OR condition2 returns FALSE only when both condition1 and condition2 must be FALSE. NOT(condition). Returns the logical opposite of condition.
15
CS105 Fall 200915 AND, OR, and NOT in Excel In Excel, AND, OR, and NOT are functions. AND(condition1, condition2). means condition1 AND condition2 OR(condition1, condition2). means condition1 OR condition2 NOT(condition). means the same as the normal meaning of NOT
16
CS105 Fall 200916 Using AND to Check Two Conditions There is an alternative way to write the IF statement in cell H3. We want the revenue to be displayed in H3 if the product is “Lively Lemon Tea” AND the region is “East”: =IF( AND( $C3="East", $A3=H$2), $D3, 0)
17
CS105 Fall 200917 Table Lookups In this course, we use two Excel functions for doing table lookups: HLOOKUP and VLOOKUP For HLOOKUP, we need to know The value that we’re looking up. The range of the table. Where its first row stores ascending values. The row index that stores the looked up result For VLOOKUP, it’s similar, except the table is vertical.
18
CS105 Fall 200918 Find Sale Rating What formula to put in K3? =HLOOKUP(D3,F28:J29,2) What are we missing? Fill in cells K4:K26 Where to put the “$” The lookup value Range address of the table The rating row index
19
CS105 Fall 200919 Working with Multiple Worksheets Suppose we want to calculate the total tea sales… Go to the ‘Statistics’ worksheet. In cell A8, put a formula to add up the range E3:E26 of the 'Tea Data' worksheet. The formula is =SUM('Tea Data'!E3:E26) Use the fill handle to copy the formula to B8 and C8. Compute the grand total of tea sales in cell D8.
20
Add a pie chart Let’s add a pie chart in “Statistics” worksheet Insert a Pie Chart You should know how to Select data to display in the chart Customize the “look-and- feel” of the chart CS105 Fall 200920
21
CS105 Fall 200921 What you should know? The formula =IF($A3=E$2, $D3, 0) =IF($C3=“East”, IF( $A3 = H$2, $D3, 0), 0) =IF( AND( $C3="East", $A3=H$2), $D3, 0) =HLOOKUP(D3,$F$28:$J$29,2) =SUM( 'Tea Data' !E3:E26) How to add and customize your pie chart Let Excel do all the hard work for you !
22
Exercises In columns K, L, and M, compute the sales of the teas for all regions except the west region. In column N, find the sales of the teas for all regions during the months of January and February (Note: Do not split the sales up into multiple columns by Product). Repeat question 2; but this time, do split the sales up into multiple columns by Product. Put these answers in columns O, P, and Q (Note: There are many possible solutions). CS105 Fall 200922
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.