1 Tutorial 7: Using Advanced Functions, Conditional Formatting and Filtering Objectives: Understand the use of structured references Evaluate single and multiple conditions using the IF function Evaluate multiple conditions using the AND and OR functions Nest functions Use the VLOOKUP function Check for errors with conditional formatting and IFERROR Summarize data using the COUNTIF, SUMIF and AVERAGEIF function for a single condition Summarize data using the COUNTIFS, SUMIFS and AVERAGEIFS function for a multiple conditions Use advanced filters and Database functions Case: Talent Tracs is a software development co. for the music and entertainment industry. Has over 100 employees and HR manager needs to maintain info on all these employees from basic data :name, gender, sex etc.. to more detailed info about their benefit choices and deductions. Open Employee Data workbook. Look at Employees worksheet. This has already been defined as a table to take advantage of the formatting and ability to have the total row. Need to name it Employee. Go to Table Tools Design and give the Table the Name Employee. Care has been taken in defining the different fields of data: 1. Fields require a minimum of maintenance. Age is not entered but instead entered birthdate, if need to can always calculate the Age Same with Years of Service. 2. Small manageable units of data example separate First and Last Name, separate address into city, state, zip 3. If a field is numeric but is to be treated as text ( example telephone numbers, social security, zip code) format it as text enter a number preceded by a Initially we will work with a simple If function to determine the premium for insurance for an employee who has selected this as an option. Premium is computed as.001 or.1% of their annual salary provided the employee has indicated that they want this insurance ie. col H is Y
2 Decision structure on p. 341 figure 7-2 Create a new calculated column. In cell N1 enter the the label Life Ins Premium and see how the table expands to include this column. Use the If function to perform this computation in cell N2. If you begin to type =If( and then point you will see structured references to elements of the table) We want to defer this concept for a little bit, so let s actually type in what we want. =if(h2= Y,k2*.001,0) BECAUSE IT IS A TABLE, the entire column is calculated. To format simply place insertion pointer in column heading H1 and when you see the down arrow, click and select the desired format. No w suppose that a 401 K deduction is available to employees who satisfy the conditions that they have been employed for at least a year and also that they are Full time employees. The amount of this deduction is 3% of their salary. Consider, how to generate this double condition See flowchart p. 343 Figure 7.5 Could use a nested If =If(m2>=1, if(g2= FT,.03*k2,0),0) Let s try it in column O O1 should have label 401K and O2 should have formula. Alternately you can use =And function which returns a true value provided all conditions specified are true. Can have up to 255 conditions specified). Delete results in col O and just enter And function to see how it works. Once students understand what the And function does.talk about nesting it. =If(And(G2= FT,M2>=1),k2*.03,0)
3 Structured References: Remember how we tried to use the mouse to select cell locations in creating our formulas, and we indicated that the formula looked differently because we were working in a table. Let s revisist that concept. What we saw was structured references. A structured reference can be an actual table name or column header. In our case table name is Employee and if want to look at column header within, use a column qualifier Employee[Annual Salary] ***This is considered to be fully qualified [Annual Salary] ***Not fully qualified As long as a reference is made within the excel Table then the table name need not be included but if outside of the table then it must be fully qualified. Let s change what we did for Life Insurance to (1)unqualified and (2) fully qualified 1. =if(*add Life Ins+= Y,*Annual Salary+*.001,0) Notice what happens when you type [ 2. =if(employee*add Life Ins+= Y,Employee*Annual Salary+*.001,0) Look at additional qualifiers on p. 345 #All entire table, all data, headers, total row if displayed #Data ---just data Employee[#All] Employee[#Data] #Headers just headers #Totals just total row..if not shown then an error is returned #ThisRow the current row in the specified column of the table Now let s delete the formula in column O and replace with structured references p. 345 =If(And(*Job Status+= FT,*Years Service+>=1),*Annual Salary+*.03,0) Ask them to follow the text Look at DatedIf function p. 348 Must have Analysis toolpack add in (Options Add-Ins) calculates the difference between two dates and shows the result in months, days or years. =DatedIF(starting date of period,ending date of period, Interval) where interval can be d, or M or Y meaning that you wish to calculate the number of complete days, months, or years between these dates. Look at Years of service and then use GoTo to move to cell AE2 to see what s there
4 Nested If Now let s extend this concept of nested ifs.suppose the company has decided to issue bonus based on grades There are only three paygrades for this company ie. grade of 1 will receive 2500, grade of 2 will receive 5000 and Grade of 3 will receive 7500 and if anything else is specified, it is an invalid code. See Figure 7-10 on p. 349 =if([pay grade]=1, 2500, if([pay grade+=2, 5000, if(*pay grade+=3, 7500, Invalid Grade ))) Or function Works like And function only one condition must be true for it to return a true Good for criteria providing for either or. Example supposing a decision is made to eliminate bonuses for employees who have worked less than a year or for those employees who earn more than 100,000. Look at p. 352 =if(or([years of service)<1, [Annual Salary] >100000),0, if[pay grade]=1, 2500, if([pay grade]=2, 5000, if(*pay grade+=3, 7500, Invalid Grade ))) More on understanding nested ifs: Think about the decision that is made in grading: If grade >=90 then A otherwise if grade >=80 then B otherwise if grade >=70 then C otherwise if grade >=60 then D otherwise F. Compose this nested If function. =if(*grade+>=90, A,If(*grade+>=80, B,If(*grade+>=70, C,if (*grade+>=60, D, F ))))
5 Lookup Tables An alternative sometimes to using Nested If statements is the use of Lookup Tables. Take the example presented in the text where each employee of Talent Tracs is given the option of selecting different health coverage. HMOF Family at $1500 HMOI Individual at $875 PPOF Family at $1650 PPOI Individual at $950 None $0 Talent Tracs pays for all different rates. In column L is employee health plan code Could devise an IF = If(*Health Plan+= HMOF,1500, If(*Health Plan+= HMOI,875, If ((*Health Plan+ = PPOF, 1650,IF([Health Plan+ = PPOI, 950,0)))) Could have used cell addresses of $ amounts Lookup Tables!$c$4 etc Instead we will use a Lookup Table and the Vlookup function. A Lookup Table is a table that organizes data into categories and consists of 2 parts o Compare values in 1 st column which are matched to a lookup value specified in Vlookup function o Adjacent columns which contain values that are returned depending on the match. =Vlookup(lookup value, lookup table(either table name or range),col index (what you want to retrieve), range lookup (False if exact or True if within a range) Create column Q and in Q1 enter Health Cost. In Q2 enter Vlookup and then go back and multiply formula in Q2 since this was a monthly amount and Talent Tracs wants annual amount. If you wish to do an approximate match ie. within a range of values then set rangelookup to True. Add a new column R which will reflect an Award that is given based on years of service.
6 Look at the Lookup table. Years of Service Recognition Award 0 $ - 1 $ 100 3 $ 200 5 $ 300 7 $ 500 Essentially if years of service is less than 1 year no award >= 1 and < 3 100 >=3 and <5 200 >=5 and <7 300 > =7 500 Look at page 359 for an example used for grading. Checking for Data Entry Errors Using Conditional Formatting you can check data for duplicates using the Highlight cells option. Follow p. 361 You can also specify your own rule for formatting by selecting New Rule and entering a formula that will result in a true or false condition. Start it with an = but it can simply be in the form of =C2<D2. Follow Insight on p. 362 You can edit existing conditional formatting rules in the Manage Rules option for Conditional Formatting Follow p. 363 Using the IFError function When an error occurs in Excel, you get vague error messages such as #N/A (value is not available to a formula or function) or #DIV/0! See table on p. 365. Can make these more descriptive by the use of the IfError function. =iferror(expression, value or message If an error occurs) Example: =iferror(b12/b14, B14 contains a zero value )
7 Take this and apply to Vlookup function p.366 =IfError(Vlookup(l2,HealthPlanRates,2,False), Invalid Code ) Summarizing Data Conditionally You can use the basic statistical functions of Sum, Count, Average with a condition by choosing: Countif =CountIf(range, criteria) where range is the one that is to be matched to the criteria and counted. Example: =CountIf(Employee*Location+, Nashville ) Here Employee[Location] will be counted if its contents match Nashville SumIf and AverageIf =SumIf(range,criteria,range to sum) In other words the additional range to sum is added to indicate what is the range that will be summed. since the first specified is the one that is matched to the criteria. Example: =SumIf(Employee*Location+, Nashville,Employee*Bonus]) Here if Employee[Location] matches Nashville, then the Bonus for that employee will be added to the sum. =AverageIf(range,criteria,range to average) works the same way but result in the average Criteria must be enclosed in and could be a text string that you want to match or an expression with a conditional operator. see p. 368-370 Extend the capability of these functions to encompass multiple ranges with different criteria SumIFS and CountIFS and AverageIfs Example: =Countifs(Employee[Job Status+, FT,Employee*Sex+, F,Employee*Annual Salary+, >50000 ) Here you have specified three different criteria that you will use to determine whether to add to a count, (all criteria must be satisfied). If an employee is Ft, female and earns more than $50,000, then that record will be included in the count.
8 You can specify up to 127 different criteria. The SumIFs and AverageIFs are a little different in that you specify a range to sum or average, and then multiple criteria that you will use to decide if a value will be included in sum. Previously in the SumIf and AverageIf the range being summed or averaged was last, now it is first. Example: =Sumifs(Employee[Annual Salary], Employee*Location+, Austen,Employee*Hire Date+, >=1/1/2008, Employee[Job Status+, FT ) explain what this means. The annual salary of an employee will be added to the sum provided the employee is from Austen and is Full time and was hired after Jan. 1, 2008. Example: =AverageIFS(Employee[Annual Salary], Employee*Sex+, M,Employee*Years of Service+, >=5 ) The annual salary of male employees who have worked more than 5 years is included in the average. Session 7.3 Using Advanced Filtering This feature allows you to perform multiple And/Or conditions across multiple fields. To do this, you must define a criteria range somewhere in the worksheet. Easiest way is to copy the headings from your table. Place the criteria that you are testing for under the appropriate field name. If they are on the same row, it is an AND condition. If on different rows, then it is OR. Using our table headers as an example Employees who are FT and have salaries greater than $50,000 Job Status Add Life Ins Grade Type Annual Salary = FT >50000 Health Plan Years Service Life Ins Premium 401 K Raise Employees who are FT or have salaries greater than $50,000 (Note the different lines) Job Status = FT Add Life Ins Grade Type Annual Salary Health Plan Years Service Life Ins Premium 401 K Raise >50000
9 What about Employees who are either FT and earn < 30000 or those that are PT and are Salaried, code S in type. Job Status Add Life Ins Grade Type Annual Salary = FT <30000 Health Plan Years Service Life Ins Premium 401 K Raise = PT = S Conditions are formed in different ways depending upon what you wish to check for. For values, it is pretty clear what is meant. value - for an exact match either use = or simply state the number (or same if using a date) text for an exact match must use = =string begins with simply specify the string greater than or less than alphabetically >letter between : beginning >= beginning text string and ending <=ending text string (These must be in separate cells so you can repeat a header if necessary. Wild card specifications can be used to find things in between a word *church* will find any string that contains the word church in it somewhere. Look at top of p. 376. This shows that an exact match is requested. If you simply type = Home or Home any string containing Home including Homebound and Homeward would match whereas = =Home requires an exact match. Goto p. 376 and create the Criteria range.
10 Using Database functions to summarize: Database functions provide an additional way to summarize data. More available than simply sum, count and average. You also have DMax, Dmin, DCountA(only non-blank cells are included), DSTDEV =DfunctionName(table range, column to summarize, criteria range) Example: Establish criteria: Health Plan HMO Type S If want all Salaried employees who have selected an HMO either HMOI or HMOF, simply type in HMO under Health Plan and under Type place and S Now you can enter a database function such as =DCount(Employee, ID, criteria range) Note here we only specify the name of the column and not the whole column as we have done in the past. i.e. Employee*ID+ would not work.why do you think that happens?????
11