Date post: | 22-Dec-2015 |
Category: |
Documents |
Upload: | giana-foulkes |
View: | 225 times |
Download: | 3 times |
# 1
CS 105
Functions, IF FunctionsCS 105
Functions, IF Functions
What is a function?
What is an IF function? A PMT function?
What is a condition?
What is nesting?
CS 105 Spring 2010
# 2CS 105 Spring 2010
Functions Functions
• An Excel command that does a specific task
• Here’s a common function in Excel:
SUM(A2:B5)• This function’s task: sum all cell values
described within the parentheses (here, the range A2:B5)– the answer is called the function’s return
value
• Why functions? Define once, use many times– simply change the stuff within parentheses– called the arguments of the function
# 3CS 105 Spring 2010
Arguments
Arguments
• A function has a name and arguments• Arguments can be data, cell names/ranges or
other functions• Examples:
SQRT (9) one argument
AVERAGE (A3, A5, A7) three arguments
SUM (A1:A10, Totals) two arguments (a range
and the name of a range)
# 4CS 105 Spring 2010
Built-in functionsBuilt-in functions
• Excel comes pre-loaded with many useful functions
• Categories include:– Math & Trig e.g., SQRT, ABS, COUNT, COUNTA,…– Statistical e.g., AVG– Financial e.g. PMT– Text e.g. CONCATENATE
• Later, we will see how to write our own functions to extend Excel’s “toolkit” or “library”
# 5CS 105 Spring 2010
PMT function
• PMT function requires interest rate/period, number of payments, and amount of loan
• Establish PMT– Amount of loan
– Down payment
– Interest rate/12
– Term (in months)
# 6CS 105 Spring 2010
As in…
# 7CS 105 Spring 2010
Note:
• Watch out! Repayment is by default from the bank’s point of view (returns a negative number, and we want a positive number).
• In order to find our payment, we make the final number negative
# 8
Quiz on PMT
• Say the interest on a car is 18% a year. In calculating the interest PER MONTH you:
A. Pay 18% interest each monthB. Pay 18% divided by 12 C. Pay 18% multiplied by 12
CS 105 Spring 2010
# 9CS 105 Spring 2010
Using Goal Seek • I want to pay only $200 a month. What car can I afford?– Change payment
total by changing one of the above variables
– The top value must have a formula in it
– Goal: $200– Computer calculates
the value of the car you can afford
Data Tab inExcel 2007
# 10
• Suppose we want formula #1 under some conditions, and a different formula #2 under other conditions
• Example: How does the ABS function work?• ABS(A5) = A5 if A5 >= 0, but• ABS(A5) = -A5 if A5 < 0
• Visually:
CS 105 Spring 2010
IF: adding power to functions
True
A5 >= 0
If
False
A5 -A5
# 11CS 105 Spring 2010
The IF function
Apply formula #1 (after first comma)
True
Apply formula #2(after second comma)
Condition
If
False
# 12CS 105 Spring 2010
How the IF function works: How the IF function works:
eg, single IF statement looks like this:
IF(A2>90, “A”, “B”)
IF (logical test, value if true, value if false)
Note: string data in a formula must be surrounded by “ ”, why?
# 13CS 105 Spring 2010
Commission example
If TEESALES sells $100,000 worth of tee shirts, the sales commission rate will be 6%. If the sales total is less than $100,000, the rate will be only 5%.
Finding the Commissionfor sales >= $100,000, pay 6% of salesfor sales < $100000, pay 5% of sales
# 14CS 105 Spring 2010
Example IF function wizard
Example IF function wizard
An IF function tests for a condition
You can type the IF function directly in the formula box or use the dialog box of the IF Function
# 15CS 105 Spring 2010
Example of IF Example of IF
=IF(B3>=100000, .06*B3, .05* B3)
B3>=100000?
.06*B3
TRUE
.05*B3
FALSE
# 16CS 105 Spring 2010
Nested IFsNested IFs
• If TEESALES sells $100,000 worth of tee shirts, the sales commission rate will be 6%.
• If the sales total is equal to or more than $80,000, but less than $100,000, the rate will be 5%.
• If total sales are below $80,000, the rate will be 3.5% of sales.
# 17CS 105 Spring 2010
Example 2 of IF Example 2 of IF
B3>=100000?
.06*B3
.035* B3
TRUE
FALSE? Then another test...
.05*B3
TRUE FALSE
=IF( B3>=100000, .06*B3, IF(B3>=80000, .05*B3, .035*B3) )
B3>=80000?
# 18CS 105 Spring 2010
Practice with Relational Operators Practice with Relational Operators
• A1 = B1 -- FALSE• A1 <> B1 -- TRUE
• A1 = B2 -- FALSE• A1 < B1 -- TRUE
• A1 < B2 -- TRUE• A1 = A2 -- TRUE
• A1 >= A2 -- TRUE• A2 > B2 -- FALSE
# 19CS 105 Spring 2010
AND, OR, NOT Functions
Formula view
Output of formulas:
# 20CS 105 Spring 2010
COUNTIF Function
• Syntax: COUNTIF(Range, Criteria)• Can be used on a summary worksheet, as in
lab
Download employee.xls to practice this
# 21CS 105 Spring 2010
SUMIF Function
• The SUMIF function adds figures to a total only if they match a certain criterion
• The syntax is SUMIF( range, criteria to check, range where numbers are)
# 22
Text Functions• Concatenation (putting two words together)
• Concatenation can be done by a function– e.g. =CONCATENATE(B3,C4)
• Operands can be :
– character strings: “Tarzan” & “Jane”– cell addresses containing text values:
B3• Concatenation can also be done by using an operator &
e.g. = B3 & C4
CS 105 Spring 2009
# 23
Adding a space
• Strings in formulas must always appear in quotes in Excel.
• To add a space, just put it between quotes. • Remember, there is an ASCII value for a
space!• You can also put a space between the quote
and the start of WaterCS 105 Spring 2009
# 24CS 105 Spring 2010
To Summarize
• What is a function?
• What is an IF function? A PMT function?
• What is a condition?
• What is nesting?