COMPREHENSIVE
Using Function
Prepared by:Prof. Rubilee S. Mariano
XPXPObjectives• Evaluate a single condition using the IF function• Evaluate multiple conditions using the AND function• Calculate different series of outcomes by nesting IF
functions• Test whether one or more conditions are true with
the OR function
New Perspectives on Microsoft Office Excel 2007 2
XPXPWorking with Logical Functions• IF function• The Excel IF function checks to see if a certain
condition is true or false. If the condition is true, the function will do one thing, if the condition is false, the function will do something else.
• IF Function Format– IF(logical_test, value_if_true, [value_if_false])
New Perspectives on Microsoft Office Excel 2007 3
XPXPExample, we will try to test if the value in column A3 is greater than the value in column B3. If it is, the IF function will place the statement "A is larger" in column D. If it is not, the IF function will place the statement "B is larger" in column D.
• Our IF function will be entered into cell D1 and it looks like this:
• =IF(A3 > B3,"A is larger","B is larger") Note: the two text statements "A is larger" and "B
is larger" are enclosed in quotations. In order to add text to an Excel IF Function, it must be enclosed in quotation marks.
New Perspectives on Microsoft Office Excel 2007 4
XPXP
New Perspectives on Microsoft Office Excel 2007 5
Parts of the Excel IF function
Inside the round brackets there are three parts or arguments to an IF Function.
The Arguments •the logic test - is A3 > B3 •the value if true - is "A is larger" •the value if false - is "B is larger“
Between each argument of the IF function, the comma is used as a separator. The comma is what tells Excel when each argument of IF function ends and the next section begins.
XPXP
New Perspectives on Microsoft Office Excel 2007 6
Adding Separators Therefore, as we complete the IF function, we will add two separators one between the logical test and the “value if true” arguments one between the “value if true” and the “value if false” arguments.
IF(logical_test, value_if_true, [value_if_false])Writing the IF Function Logical Test The logical test is always a comparison between two amounts,thus, we are comparing the values in cells A3 and B3. Between the two values we place a comparison operator.
The comparison operators that can be used in the logical test portion of an Excel IF function are:
Equals (=) Less than (<) Less than or equal to (<=) Greater than (>) Greater than or equal to (>=) Not equal to (<>)
XPXP
New Perspectives on Microsoft Office Excel 2007 7
Exercise 1. Using Excel's IF Function
A. Write an IF statement so that if the number in Cell A2 is less than 100 the formula displays the text "Within budget", otherwise the formula displays the text "Over budget“ in cell B2.
A B
1 THE DATA RESULT
2 50
B. Write an IF statement so that if the number in Cell A2 is 100 then the formula sums the range B5:B15. Otherwise, the formula returns a blank (empty text).
XPXPNESTED IF Functions• A nested IF function is when one IF function is placed inside
another IF function to test an additional condition• =IF([Pay Grade]=1,2500,IF([Pay Grade]=2,5000, IF([Pay Grade]=3,
7500,"Invalid pay grade")))
New Perspectives on Microsoft Office Excel 2007 8
XPXP
New Perspectives on Microsoft Office Excel 2007 9
A
1 SCORES
2 45
3 90
4 78
Exercise 3. More Practice with IF Functions IF SCORES IS THEN RETURN
GREATER THAN 89 A
FROM 80 TO 89 B
FROM 70 TO 79 C
FROM 60 TO 69 D
Below 60 F
A. Write a NESTED IF statement assigning a letter grade to the score in Cell A2.
ANSPROB
XPXP
New Perspectives on Microsoft Office Excel 2007 10
AND FunctionThe AND function is one of Excel’s Logical Functions. Like most logical functions, the output from the AND function is either the word TRUE or FALSE. To determine whether the output will be TRUE or FALSE, the function evaluates at least one mathematical expression located in another cell in the spreadsheet.
XPXP
New Perspectives on Microsoft Office Excel 2007 11
Example AND FunctionNote: This example is typed in cell C1.
=AND (B1>100, B2>100, B3>100)If all three of these cells (B1,B2, and B3) contain a value greater than 100, the output for the AND function in cell C1 will be TRUE. If any of these cells have numbers less than or equal to 100, the output for the AND function will be FALSE.
XPXP
New Perspectives on Microsoft Office Excel 2007 12
Combining the AND Function with Other Functions By itself, the AND function has limited usefulness. By combining it with another function, such as the IF function, the AND function can increase the capabilities of your spreadsheet. Example – Nesting the AND function inside the IF function =IF(AND(B1>100,B2>100,B3>100),”Over budget”,”Acceptable”)Assuming this function is located in cell C1, if all three of these cells (B1,B2, and B3) contains a value greater than 100, the IF function will show the statement Over Budget in cell C1. If any of these three cells contain a number less than or equal to 100, the IF function shows the statement Acceptable in cell C1.
XPXP
New Perspectives on Microsoft Office Excel 2007 13
Note: In Excel 2007, the AND function can contain a maximum of 255 expressions. For earlier versions of Excel, the limit is 30 expressions.
Exercise 1. Using Excel's AND
A. Write an AND formula to determine if A2>A3 and A2<A4 is a true or false statement.
A
1 THE DATA
2 5
3 9
4 15
XPXP
New Perspectives on Microsoft Office Excel 2007 14
SOLUTION : A. =AND(A2>A3, A2<A4)
PROB. CREATE A FORMULA USING IF AND FUNCTION BASED ON THE CONDITION THAT THE STUDENT COULD ONLY PASS THE SUBJECT IF HIS/HER GRADE IS GREATER THAN 75 AND ABSENCES IS LESS THAN 10.
XPXP
New Perspectives on Microsoft Office Excel 2007 15
Exercise2 :
A B C D E
1 Name District Sales Emp. Yrs Job Level
2 Linda East $20,000.00 2
3 Joe West $42,302.00 9
4 Bill East $53,001.00 3
5 Mary South $12,000.00 12
6 Mark South $ 2,050.00 6
7 John North $9,000.00 0
8 Ted East $40,000.00 4
Problem:
suppose you want a formula in column E that will assign a job level based on two different criteria: Salespeople who have been employed for more than 5 years AND have annual sales of more than $10,000 should be assigned a job level code of 2, and all others should have a job level code of 1.
XPXP
New Perspectives on Microsoft Office Excel 2007 16
SOLUTION:=IF(AND(D2>5,C2>10000),2,1)
The OR function is one of Excel's Logical Functions. Like most logical functions, the output from the OR function is either the word TRUE or FALSE. To determine whether the output will be TRUE or FALSE, the function evaluates at least one mathematical expression located in another cell in the spreadsheet. Example OR FunctionNote: This example is typed in cell c1 If any of these three cells (B1,B2, or B3) contains a value greater than 100, the output for the OR function in cell C1 will be TRUE. If all three cells have numbers less than or equal to 100, the output for the OR function will be FALSE.
XPXP
New Perspectives on Microsoft Office Excel 2007 17
Combining the OR Function with Other FunctionsBy itself, the OR function has limited usefulness. By combining it with another function, such as the IF function, the OR function can increase the capabilities of your spreadsheet. Example – Nesting an OR function inside an IF function =IF(OR(B1>100,B2>100,B3>100),”Over Budget”,”Acceptable”)
XPXP
New Perspectives on Microsoft Office Excel 2007 18
Assuming this function is located in cell C1, if any of these three cells (B1,B2, or B3) contains a value greater than 100, the IF function will show the statement Over Budget in cell C1. If all three cells have numbers less than or equal to 100, the IF function shows the statement Acceptable in cell C1.
Note: In Excel 2007, the OR function can contain a maximum of 255 expressions. For earlier versions of Excel, the limit is 30 expressions.
XPXP
New Perspectives on Microsoft Office Excel 2007 19
Problem:
A
1 THE DATA
2 5
3 9
4 15
B. Write an OR formula to determine if A2>A3 or A2<A4 is a true or false statement.
XPXP
New Perspectives on Microsoft Office Excel 2007 20
Problem:
Create a formula using the If function to return 25 if cell A1 > 100 and cell B1 < 200. Otherwise, it should return 0.
XPXP
New Perspectives on Microsoft Office Excel 2007 21
THANK YOU!!!
Ans.=IF(AND(A1>100,B1<200),25,0)
XPXPUsing Lookup Tables and Functions• A lookup table is a table that organizes data you want
to retrieve into different categories• The categories for the lookup table, called compare
values, are located in the table’s first column or row• To retrieve a particular value from the table, a lookup
value (the value you are trying to find) needs to match the compare values
• VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])
New Perspectives on Microsoft Office Excel 2007 22
XPXPUsing Lookup Tables and Functions
New Perspectives on Microsoft Office Excel 2007 23
XPXPUsing Lookup Tables and Functions
New Perspectives on Microsoft Office Excel 2007 24
XPXPHighlighting Duplicate Records with a Custom Format• Select the column you want to search for duplicates• In the Styles group on the Home tab, click the
Conditional Formatting button, point to Highlight Cells Rules, and then click Duplicate Values
• Click the values with arrow, then click Custom Format• In the Format Cells dialog box, set the formatting you
want to use• Click the OK button in each dialog box
New Perspectives on Microsoft Office Excel 2007 25
XPXPHighlighting Duplicate Records with a Custom Format
New Perspectives on Microsoft Office Excel 2007 26
XPXPUsing the Conditional Formatting Rules Manager• Each time you create a conditional format, you
are defining a conditional formatting rule• A rule specifies the type of condition (such as
formatting cells greater than a specified value), the type of formatting when that condition occurs
New Perspectives on Microsoft Office Excel 2007 27
XPXPUsing the IFERROR Function• Error values such as #DIV/0!, #N/A, and #VALUE!
indicate that some element in a formula or a cell referenced in a formula is preventing Excel from returning a calculated value
• The IFERROR function can determine if a cell contains an error value and display the message you choose rather than the default error value
• =IFERROR(VLOOKUP(L2,HealthPlanRates,2,False)*12,"Invalid code")
New Perspectives on Microsoft Office Excel 2007 28
XPXPUsing the IFERROR Function
New Perspectives on Microsoft Office Excel 2007 29
XPXPSummarizing Data Conditionally• You can calculate the number of cells in a range
that match criteria you specify using the COUNTIF function, which is sometimes referred to as a conditional count
• =COUNTIF(range,criteria)• You can add the values in a range that meet
criteria you specify using the SUMIF function, which is also called a conditional sum
• =SUMIF(range,criteria[,sum_range])
New Perspectives on Microsoft Office Excel 2007 30
XPXPSummarizing Data Conditionally• You use the AVERAGEIF function to calculate the
average of values in a range that meet criteria you specify
• =AVERAGEIF(range,criteria[,average_range])
New Perspectives on Microsoft Office Excel 2007 31
XPXPSummarizing Data Conditionally• The COUNTIFS function counts the number of cells within a range
that meet multiple criteria– COUNTIFS(criteria_range1,criteria1[,criteria_range2,
criteria2...])• The SUMIFS function adds values in a range that meet multiple
criteria– SUMIFS(sum_range,criteria_range1,criteria1[,criteria_
range2, criteria2...])• The AVERAGEIFS function calculates the average of values within
a range of cells that meet multiple conditions– AVERAGEIFS(average_range,criteria_range1,criteria1
[,criteria_range2, criteria2...])
New Perspectives on Microsoft Office Excel 2007 32
XPXPUsing Advanced Filtering• Advanced filtering, similar to filtering, displays a
subset of the rows in a table or range of data• The criteria range is an area in a worksheet,
separate from the range of data or Excel table, used to specify the criteria for the data to be displayed after the filter is applied to the table
New Perspectives on Microsoft Office Excel 2007 33
XPXPUsing Advanced Filtering
New Perspectives on Microsoft Office Excel 2007 34
XPXPUsing Advanced Filtering• Click the Data tab on the Ribbon, and then, in
the Sort & Filter group, click the Advanced button
New Perspectives on Microsoft Office Excel 2007 35
XPXPUsing Database Functions to Summarize Data• Functions that perform summary data analysis
(SUM, AVERAGE, COUNT, and so on) on a table of values based on criteria that you set are called the Database functions, or Dfunctions
• DfunctionName(table range, column to summarize, criteria range)
New Perspectives on Microsoft Office Excel 2007 36
XPXPUsing Database Functions to Summarize Data
New Perspectives on Microsoft Office Excel 2007 37
XPXPUsing Database Functions to Summarize Data
New Perspectives on Microsoft Office Excel 2007 38
Top Related