0% found this document useful (0 votes)
7 views

CS Excel

Excel

Uploaded by

cooperkreates
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

CS Excel

Excel

Uploaded by

cooperkreates
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

What is a spreadsheet?

Computer program to organize and analyze


EXCEL TUTORIAL data in tabular form.

SPREADSHEET
Presents a grid of cells, each of which can
BASICS contain text or numerical data, or results of
computation.

1 2

What is a spreadsheet? History of Spreadsheets?

Excel 2016
Optional Readings:
http://www.dssresources.com/history/sshistory.html
http://www.dssresources.com/history/mattessichspreadsheet.ht
m
Video: Cringely, Robert X. Triumph of the Nerds. Ambrose Video,
1996. (on OWL)

3 4
Fundamental Ideas Fundamental Ideas

» Cells » Cells
» Data » Data
» Coordinates » Coordinates
» Formulas » Formulas

Cells contain data


(dates, numbers,
etc.) or a formula.

5 6

Cells Fundamental Ideas


Cell referenced by
column, then number

• Cells have two aspects:


» Cells
– What they contain
» Data
– How it looks
» Coordinates Columns
• Cells contain data or computed values designated with
» Formulas letters
– Data may be numeric or text
– Cell contents may be computed by a formula
• They way the cell looks can be adjusted
Rows designated
– to help readers follow the logic of the spreadsheet with numbers
Current cell
– or be purely decorative surrounded by heavy
border

7 8
Coordinates Fundamental Ideas

• Each cell may be referred to by its » Cells


column name and row number. » Data
• Column names are given by letters: » Coordinates
– A, B, …, Z, AA, AB, …, AZ, BA, BB, …, BZ, … ZZ, » Formulas
AAA…
• Row numbers start at 1 and increase down the
page.

9 10

Formulas Formatting

• Are given by starting contents with “=”


• An “expression” follows. This may involve
– Numbers, e.g. 1, 10, 12.7, 10.2e51 (10.2 × 1051)
– Cell names, e.g. A1, B10, AA99
– Arithmetic operators, +, -, *, /
– Ranges of values, e.g. B2:E10 (upper left:lower right) Ribbon Most formatting
controls on HOME
– Function calls, e.g. LOG(1000), SUM(B2:E10) tab ribbon.

11 12
Formatting Formatting

• Cells may be formatted using Data values may be presented many ways.

– Fonts, Sizes, styles, Colours, etc.

Accessed via cell


Found on right click menu or
HOME ribbon. Ctrl-1

13 14

Formatting Formatting

Data values may be presented many ways. • It is appropriate to format cells properly
• Select the cells to format and choose the appropriate formatting option
from the menu bar
• Changes are made using formatting buttons on the Home tab.
Changes include:
▫ formatting rate as a percentage
▫ formatting a cell as currency
▫ using bolding and centering on table titles
▫ changing the font size and the color on the worksheet’s title
• Other formatting options also exist

15 16
MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Formulas Formulas
Enter an equation that Excel will compute:
Using Cell Reference:
starts with an equal (=) sign
= A6 + B8
arithmetic
operands Take the values
(+, - , *, /, etc ) currently in
cell A6 and B8
constants
add them together
-or-
cell references
place the results in
cell A11

17 18

MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Formulas Formulas

Copy and Paste: Copy and Paste - Using Cell Reference:


constants Two Options:
copy the value
currently in Relative reference
cell c7 Adjusts during a
copy operation
and paste it into
cell D11 Absolute reference
Remains constant
result: when copied
value 31 is now in
cell D11

19 20
MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Formulas Formulas

Copy and Paste - Using Cell Reference: Copy and Paste - Using Cell Reference:
Relative reference Relative reference
cell reference example:
changes based on
direction and copy the contents
number of cells of cell A11
to cell B12
example:
copy the contents over to the right
of cell A11 1 cell
to cell B12
A in A6 becomes B
B in B8 becomes C

21 22

MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Formulas Formulas

Copy and Paste - Using Cell Reference: Copy and Paste - Using Cell Reference:
Relative reference Relative reference
example: example:
copy the contents copy the contents
of cell A11 of cell A11
to cell B12 to cell B12

AND down 1 cell change relative to the


starting point
6 in A6 becomes7
8 in B8 becomes 9 1 cell over and 1 cell
down

add 1 to each value

23 24
MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Formulas Formulas

Copy and Paste - Using Cell Reference: Copy and Paste - Using Cell Reference:
Relative reference Relative reference
example: example:
Relative Reference Rules:
copy the contents copy the contents
of cell A11 of each
for cell cell
A11moved to the RIGHT : Add (+) One (1) to the COLUMN
to cell B10 to cell B10
for each cell moved to the LEFT: Subtract (-) One (1) from the COLUMN
1 cell over and 1 cell 1 cell over and 1 cell
up upeach cell moved DOWN: Add (+) One (1) to the ROW
for

for each cell moved UP: Subtract (-) One (1) from the ROW
add 1 to each add 1 to each
COLUMN value COLUMN value
subtract 1 from subtract 1 from
each ROW value each ROW value

25 26

MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Formulas Formulas

Copy and Paste - Using Cell Reference: Copy and Paste - Using Cell Reference:
Absolute reference Absolute reference
cell reference cell reference
remains the same
regardless of remains the same
direction and regardless of
number of cells direction and
number of cells
absolute referencing
requires the use of the example:
absolute symbol ($) copy the contents
of cell A11
to cell B12
preceding the
reference to be ‘anchored’

27 28
MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Formulas Formulas

Copy and Paste - Using Cell Reference: Copy and Paste - Using Cell Reference:
Absolute reference Absolute reference
example: example:
copy the contents copy the contents
of cell A11 of cell A11
to cell B12 to cell B12

over to the right AND down 1 cell


1 cell
6 in A6 stays 6
A in A6 stays A 8 in B8 stays 8
B in B8 stays B

29 30

MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Formulas Formulas

Copy and Paste - Using Cell Reference: Copy and Paste - Using Cell Reference:
Absolute reference Absolute reference
example: example:
copy the contents
copy the contents of cell A11
of cell A11 to cell B10
to cell B12
1 over and 1 up
absolute reference absolute reference
values do values do
NOT change NOT change
regardless of
regardless of direction and number
direction and number of cells
of cells

31 32
MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Formulas Formulas

Copy and Paste - Using Cell Reference: Copy and Paste - Using Cell Reference:
Mixed reference Mixed reference
row or column row or column
is relative is relative
and and
column or row column or row
is absolute is absolute

=$A6 + B$8 example:


copy the contents
$A is absolute of cell A11
6 is relative to cell C13
B is relative
$8 is absolute

33 34

MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Formulas Formulas

Copy and Paste - Using Cell Reference: Copy and Paste - Using Cell Reference:
Mixed reference Mixed reference
row or column row or column
is relative is relative
and and
column or row column or row
is absolute is absolute

over 2 cells over 2 cells


AND down 2 cells AND down 2 cells

A in $A6 stays A 6 in $A6 changes 8


8 in B$8 stays 8 B in B$8 changes D

35 36
MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Formulas Formulas (Question)

Copy and Paste - Using Cell Reference: Copy and Paste - Using Cell Reference:
Mixed reference Mixed reference
row or column row or column
is relative is relative
and and
column or row column or row
is absolute is absolute

(A11) =$A6 + B$8 example:


(C13) =$A8 + D$8 copy the contents
of cell D13
to cell B14

37 38

MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Formulas (Question) Formulas (Question)

Copy and Paste - Using Cell Reference: Copy and Paste - Using Cell Reference:
=$A6 + B$8
Mixed reference Multiplication Table
row or column create a single formula
is relative
and to be placed in
column or row
is absolute cell B8
that will compute the
example:
copy the contents results of multiplying
of cell D13 the row by the column
to cell B14
so that it can be copied
WHAT IS THE FORMULA THAT IS NOW IN CELL B14 ? and paste to all cells

39 40
MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Formulas (Question) Formulas (Question)

Copy and Paste - Using Cell Reference: - Professor develops a formula to correctly calculate
the overall marks for the students
Mixed reference
Multiplication Table
- Professor enters formula for the 1st student
BRUTE FORCE

enter individual - Once formula tested for the 1st student, formula
formulas in each cell copied into the cells for all the students in the class
- yech !!!

Which values change


- and -
Which values stay the same

41 42

MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Formulas (Question) - Calculate the marks Formulas (Question) - Calculate the marks

TASK: create the


formula using
relative and
Absolute referencing
- So the formula is
Only written once and
then can be copied to
all students

Which values change


- and -
Which values
stay the same
Formula: ( (Test 1 x T1 Weight) + (Test 2 x T2 Weight) + (Test 3 x T3 Weight) ) Formula: =D4 * D14 + E4 * E14 + F4 * F14

Formula: ( (70 x 0.25) + (80 x 0.25) + (90 x 0.50) ) = 82.5 Formula: ( (70 x 0.25) + (80 x 0.25) + (90 x 0.50) ) = 82.5

43 44
MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Formulas (Question) - Calculate the marks Formulas (HINTS)

TASK: create the - add cell references to a formula


formula using
relative and
Absolute referencing
- So the formula is
Only written once and
then can be copied to
all students
- to change the reference from absolute to relative and back

Which values change


- and -
Which values
stay the same
Formula: =D4 * $D$14 + E4 * $E$14 + F4 * $F$14

Formula: ( (70 x 0.25) + (80 x 0.25) + (90 x 0.50) ) = 82.5

45 46

MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Formulas (HINTS) Formulas (Question) - Calculate the marks

BEDMAS: TASK: create the


formula using
relative and
Absolute referencing
- So the formula is
Only written once and
then can be copied to
all students

Which values change


- and -
Which values
stay the same
Formula: =(D4 * $D$14) + (E4 * $E$14) + (F4 * $F$14)

Formula: ( (70 x 0.25) + (80 x 0.25) + (90 x 0.50) ) = 82.5

47 48
MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Formulas (Question) - Calculate the marks Formulas (Question) - Calculate the marks
copy and paste ( pull down ) the original formula copy and paste ( pull down ) the original formula

49 50

MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Formulas (Question) - Calculate the marks Formulas (Question) - Calculate the marks
change just the exam weights - averages change automatically ! change just the exam weights - averages change automatically !

51 52
Copy and Paste Copy and Paste of Formulas
• When pasting formulas, cell references like A10 are
relative!
• Can copy or move the contents and the • That is, the row and column are taken as offsets from
formatting of cells from one place to another. where the original formula was placed.

• On Windows, this is done with Control-C/Control-V


• On Mac, it is done with -C, -V copy paste
• This is exactly what is needed when copying blocks with
formulas computing values from within the block.
53 54

Copy and Paste of Formulas Copy and Paste of Formulas

• To give absolute cell positions, use “$” in front of the


column name, the row number, or both. What if we pasted C1 into E3?

copy paste

• This can be used in ranges as well, e.g. $A$1:H$2


55 56
Copy and Paste of Formulas Copy and Paste of Formulas
What if we pasted C1 into E3? What if we pasted C1 into
E3?

• Absolute references are “fixed” when pasted/dragged: • Absolute references are “fixed” when pasted/dragged:

copy paste copy paste


57 58

Example 1: Part 1 Example 1: Part 1

Calculate total precipitation in Cell D1 and Calculate total precipitation in Cell D1 and
paste it into cells D3 to D9 paste it into cells D3 to D9
59 60
Example 1: Part 1 Example 1: Part 2

Calculate total precipitation in Cell D1 and Calculate the difference between the total precipitation
paste it into cells D3 to D9 for each city and the total record precipitation.
61 62

Example 1: Part 2 Example 1: Part 2

Seems to work
for this cell!

Calculate the difference between the total precipitation Calculate the difference between the total precipitation
for each city and the total record precipitation. for each city and the total record precipitation.
63 64
Example 1: Part 2 Example 1: Part 2

Something has gone


wrong.
26.84 - 26.55 ≠ 26.84

Referencing wrong
cell!
Calculate the difference between the total precipitation Calculate the difference between the total precipitation
for each city and the total record precipitation. for each city and the total record precipitation.
65 66

Example 1: Part 2 Example 1: Part 2

Need to use absolute


reference for row.
=D3-D$9

Calculate the difference between the total precipitation


What went wrong? for each city and the total record precipitation.
67 68
Example 1: Part 2 Example 2:

Calculate the difference between the total precipitation Calculate the average for each student using the
for each city and the total record precipitation. number of students in cell B1.
69 70

Example 2: Example 2:

Average over 100!


What went wrong?

Calculate the average for each student using the Calculate the average for each student using the
number of students in cell B1. number of students in cell B1.
71 72
Example 2: Example 2:

Need to follow order of operations! Now copy to other cells…

Calculate the average for each student using the Calculate the average for each student using the
number of students in cell B1. number of students in cell B1.
73 74

Example 2: Example 2:

Something Needed to use


went wrong absolute
again! reference for the
column this time.
Calculate the average for each student using the Calculate the average for each student using the
number of students in cell B1. number of students in cell B1.
75 76
Example 2: Example 2:

Calculate the average for each student using the Calculate the average for each student using the
number of students in cell B1. number of students in cell B1.
77 78

Operators Operators

Examples

• Arithmetic • Arithmetic =2^4 + 2^2 20


+, -, *, /, ^ (power) +, -, *, /, ^ (power) =(52+74+96)/3 74
• Comparison • Comparison
=5<>3 TRUE
=, >, <, >=, <=, <> =, >, <, >=, <=, <> =6>=7 FALSE
• Text • Text =7&10&9 7109
& (concatenation) “Wednes” & “day” & (concatenation) =“Comp”&”Sci” CompSci

79 80
Operators Example 3:
Examples

• Arithmetic =2^4 + 2^2 20


+, -, *, /, ^ (power) =(52+74+96)/3
Write a formula to calculate:
74
• Comparison =5<>3 100
TRUE 100
=, >, <, >=, <=, <> =6>=7 FALSE 1
• Text =7&10&9 7109
Where X is cell A1.
& (concatenation) =“Comp”&”Sci” CompSci

• Used with cell references: =100 – 100 / (1 + A1)


=A1 + $B$2 – A$6 * $B3 =B1 & B3
81 82

Example 4: Activity Try to solve before viewing the next slide!

Using the values in columns G and H (in the same row),


Write a formula to calculate: what formulas will I need to put in the cells in column I to
arrive at the desired output?
13
14
Where X is cell A1 and Y is B2.

=((A1 * 13) + B2) / 14

83 84
Activity
Solutions:

EXCEL TUTORIAL
BOOLEAN LOGIC

85 86

MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Microsoft Excel in depth Boolean Expressions

If today is Tuesday and it is February


- Boolean Logic
- Logical expressions… then I will bake an apple pie

otherwise I will bake a pumpkin pie

WHAT WILL I DO?


HOW DID YOU DECIDE?

87 88
MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Boolean Expressions Boolean Expressions

Rewriting the expression: Rewriting the expression:

IF (today is Tuesday) AND (it is September) IF (today is Tuesday) AND (it is September)
THEN I will bake an apple pie THEN I will bake an apple pie
OTHERWISE (else) I will bake a pumpkin pie OTHERWISE (else) I will bake a pumpkin pie

AND is called a boolean operator


- What values can (today is Tuesday) be? (today is Tuesday) is a boolean variable
(it is September) is a boolean variable

89 90

MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Boolean Expressions Boolean Expressions

Rewriting the expression: Rewriting the expression:

IF (today is Tuesday) AND (it is September) IF (today is Tuesday) AND (it is September)
THEN I will bake an apple pie
THEN I will bake an apple pie
OTHERWISE (else) I will bake a pumpkin pie
OTHERWISE (else) I will bake a pumpkin pie
boolean variable: (today is Tuesday)
boolean variable: (it is September)
((today is Tuesday) AND (it is September)) is a boolean expression boolean operator: AND
boolean expression: ((today is Tuesday) AND (it is September))

91 92
MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Boolean Expressions Boolean Expressions

Example 2: We use Boolean expressions everyday


IF my salary is greater than $100,000.00 » Boolean expressions are part of our decision making process
THEN I will go to Hawaii,
OTHERWISE I will go to Kitchener » We use
⋄ Boolean variables
⋄ Relational operators
Rewritten: ⋄ Boolean operators
IF (salary > 100000)
THEN I will go to Hawaii
ELSE I will go to Kitchener

93 94

MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Boolean Operators - NOT - AND - OR Boolean Operators


AND OR NOT » Relational operators
A B result A B result
⋄ yield Boolean results (“true” or “false”)
A result
F F F F F F » There are six relational operators
F T ⋄ Equal to =
F T F F T T
T F F T F T
⋄ Not equal to <>
T F ⋄ Less than <
T T T T T T
⋄ Less than of equal to <=
⋄ Greater than >
⋄ Greater than or equal to >=

95 96
MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Boolean Operators Boolean Operators - in Excel

» Three conjunctive Boolean operators » Boolean operators (AND, OR and NOT)


⋄ Predefined functions in Excel
» NOT, AND, OR

⋄ NOT » Expression “age is NOT greater than or equal to 19”


- would be entered as
⋄ complements results of a Boolean expression
⋄ AND =NOT(Age>=19)
⋄ combines two Boolean expressions on an Excel spreadsheet
⋄ OR
⋄ combines two Boolean expressions

97 98

MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Boolean Operators - in Excel Boolean Logical Functions - ( If Statements )

» The expression: » Enables decision making in a worksheet


“balance is greater than or equal to $20.00
and
I have my ATM card” » Requires three parts ( sections ) :
would be entered as 1. Condition
=AND(Balance>=20,ATM=“true”) ⋄ Evaluates as either true or false
⋄ Uses relational operators (=, <, etc.)
» The expression: 2. Result (value) if the condition is true
“work in the R&D department
or they make more than $50,000 a year” 3. Result (value) if the condition is false
would be entered as
=OR(Depart=“R&D”,Salary>50000)

99 100
MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Boolean Logical Functions - ( If Statements ) Boolean Logical Functions - ( If Statements )

» Selects between one of two actions » Selects between one of two actions
True or False True or False
» Student earning a mark greater than or equal to 50
» Requires three parts ( sections ) : will be given a numeric grade for the course.
If they have a mark less than 50
=IF(<expression>,<true>,<false>) they will be given an “F”.
⋄ <expression> is a Boolean expression » Mark for a student is stored in cell G68
⋄ <true> part performed if expression is true
⋄ <false> part preformed if expression is false Formula:
=IF(G68>=50,G68,”F”)
⋄ decides if a numeric grade or an “F” is given

101 102

MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Boolean Logical Functions - ( If Statements ) Boolean Logical Functions - ( If Statements )

» Develop a formula to calculate a sales commission: If sales <= $1000


⋄ 5% of the total sales if the total sales are less than or then commission = 5% x sales
equal to $1,000 otherwise if sales <= $5000
then commission = 10% x sales
⋄ 10% of the total sales if the total sales are greater than otherwise commission = 15% x sales
$1,000 and less than or equal to $5,000
⋄ 15% of the total sales if the total sales are greater than
$5,000 » assume sales figure in B5
Formula:
If sales <= $1000
then commission = 5% x sales =IF (B5<= 1000, B5*.05, IF (B5 <=5000, B5*.10, B5*.15))
otherwise if sales <= $5000
then commission = 10% x sales
otherwise commission = 15% x sales

103 104
MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Boolean Logical Functions - ( If Statements ) Boolean Logical Functions - ( If Statements )

If sales <= $1000 If sales <= $1000


then commission = 5% x sales then commission = 5% x sales
otherwise if sales <= $5000 otherwise if sales <= $5000
then commission = 10% x sales then commission = 10% x sales
otherwise commission = 15% x sales otherwise commission = 15% x sales

» assume sales figure in B5


condition FALSE part » assume sales figure in B5
condition FALSE part
TRUE part
TRUE part
Formula: Formula:
=IF (B5<= 1000, B5*.05, IF (B5 <=5000, B5*.10, B5*.15)) =IF (B5<= 1000, B5*.05, IF (B5 <=5000, B5*.10, B5*.15))

=IF (B5<= 1000, B5*.05, IF (B5 <=5000, B5*.10, B5*.15))

105 106

MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Boolean Logical Functions - ( If Statements ) Boolean Logical Functions - ( If Statements )

If sales <= $1000 If sales <= $1000


then commission = 5% x sales then commission = 5% x sales
otherwise if sales <= $5000 otherwise if sales <= $5000
then commission = 10% x sales then commission = 10% x sales
otherwise commission = 15% x sales otherwise commission = 15% x sales
» assume sales figure in B5 » assume sales figure in B5

Formula: Formula:
=IF (B5<= 1000, B5*.05, IF (B5 <=5000, B5*.10, B5*.15)) =IF (B5<= 1000, B5*.05, IF (B5 <=5000, B5*.10, B5*.15))

107 108
MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Boolean Logical Functions - ( If Statements ) Boolean Logical Functions - ( If Statements )

» Logic Question. » Logic Question.


A B C D E
1 10 30 45 89
A. Laura
2 Homer Lisa Bart Marge B. Bart
3 Gord Laura Mike Andrew C. Homer
4 56 67 45 23 D. Mike
5
- B9 contains the formula:
=IF(AND((B2>40),(B6<50)),”goodbye”,"hello") What is the value of the following formula:
What would be displayed? =IF(AND((NOT(D4<25)),(B1=30)), D2, B3)

109 110

Excel Functions

What is a Function?
• Similar to but not the same as functions in math
EXCEL TUTORIAL f(x) = 10x + 5
f(x, y) = x2 + y2
EXCEL FUNCTIONS • Less rules for functions in computer science:
– Functions can have no parameters
=ROW()
– Same arguments can have different output
=RANDBETWEEN(10, 20)

111 112
Excel Functions Excel Functions

What is a Function? What is a Function?


• Similar to but not the same as functions in math • Similar to but not the same as functions in math
f(x) = 10x + 5 f(x) = 10x + 5
f(x, y) = x2 + y2 f(x, y) = x2 + y2
• Less rules for functions in computer science: • Less rules for functions in computer science:
– Functions can have no parameters Returns current row number – Functions can implement an algorithm or do something
=ROW() nonmathematical, not just a mathematical equation
– Same arguments can have different output
Random number =NOW() =ROW() =UPPER("hello world!")
=RANDBETWEEN(10, 20)
between 10 and 20

113 114

Excel Functions Excel Functions


Why do we Need Functions?
What is a Function? Previous Example #2
• Similar to but not the same as functions in math
• What if we had 100
f(x) = 10x + 5
tests?
f(x, y) = x2 + y2 • Don’t want to
reference all cells
• Less rules for functions in computer science:
by hand.
– Functions can implement an algorithm or do something
nonmathematical, not just a mathematical equation • What if we do this
Current date/time Convert string to uppercase
type of average
=NOW() =ROW() =UPPER("hello world!")
calculation a lot?

115 116
Excel Functions Excel Functions
Why do we Need Functions? Function Parts
• Functions allow us to reuse code someone else has =SUM(number1, [number2], …)
already made for us.
• Can do repetitive or tedious work for us. Function Parameters
Name
• Don’t have to understand the inner workings of the
function, just how to use it.
• Can do calculations or access data not possible with
just operations.
– Example: =NOW()
117 118

Excel Functions Excel Functions


Function Parts Example 5:

=SUM(number1, [number2], …) Update student average example (EX #2) using functions SUM
and COUNT.
Function Parameters =SUM(number1, [number2], …)
Name Arguments
Add the given numbers.
=COUNT(value1, [value2], …)
=SUM(A1, 32, 5.124, B$5, $C$6) Counts the number of numbers it is given.
Text is not counted.

119 120
Excel Functions Excel Functions
Example 5: Example 5:
Update student average example (EX #2) using functions SUM
and COUNT.
=SUM(number1, [number2], …)
Example: =SUM(5, 10, 13.5) 28.5
=COUNT(value1, [value2], …)
Example: =COUNT(5, “cat”, 13.5, “”) 2

121 122

Excel Functions Excel Functions


Example 5: Ranges

• Better way than giving each cell individually as an


argument?
• Can use a range:
B4:B6
Starting Cell Ending Cell
Contains cells:
B4, B5 and B6
123 124
Excel Functions Excel Functions
Example 5: Take 2 Example 5: Take 2

Can paste/drag ranges


just like other cell
references!

125 126

Excel Functions Excel Functions


AVERAGE Example 5: Take 3

• Better function to use?


• Maybe someone already made an average function?

=AVERAGE(number1, [number2], …)
• Returns the average of the given numbers
• As with many Excel functions, the arguments can be
cell constant values, cell references, or cell ranges.
127 128
Excel Functions Excel Functions
Example 5: Take 3 More Functions
Function(s) Description
MAX, MIN, MINIFS, Find the largest (max) or smallest (min) number given.
MAXIFS
AVERAGE, AVERAGEA, Find the average of the given numbers/range.
AVERAGEIF
STDEV.P, STDEV.S Find the standard deviation of a population (STDEV.P) or sample (STDEV,
STDEV.S).
SUM, SUMIF Find the sum of the given numbers/range (i.e. add them together).
COUNT, COUNTA, Count the number of numbers or text in the given range.
COUNTIF
DATEDIF, DAYS Find the number of days between two given dates.

PMT Calculates the payment for a loan based on constant payments and a constant
interest rate.
Many, many, more…. See Last Slide for More

129 130

Function Help Function Help


Square brackets means
optional parameter.

… means it can take more parameters of


the same type.

Once we type the ( on a valid function name,


As we type in the formula bar, Excel recommends Excel shows us the parameters it takes.
functions and gives a description.
131 132
133 134

Excel Functions
Online Help

https://support.office.com/

135 136
Excel Functions Excel Functions
Online Help Online Help

https://support.office.com/ https://support.office.com/

137 138

Excel Functions Logic Functions


Online Help Example 6:

If a student’s grade is
greater than or equal to
60 output PASS in
column C. Otherwise
output FAIL.

139 140
Logic Functions Logic Functions
Example 6: Example 7:

To pass, a student must


have a grade of 60 or
higher AND attend at
least 7 lectures.

141 142

Logic Functions “_IF” Functions


Example 7: • A number of Excel functions have an _IF variant.
• Allow for criteria to determine if value should be counted in
calculation.
• Example:
=COUTNIF(range, criteria)
• Counts numbers in range that match the given criteria.
COUNTIF(A2:A5, “apples”) number of cells containing “apples”
COUNTIF(A2:A5, B7) number of cells same as B7
COUNTIF(A2:A5, “>100”) number of cells > 100
COUNTIF(A2:A5, “>” & B7) number of cells > B7

143 144
“_IF” Functions “_A” Functions
» Variant of functions like AVERAGE, COUNT, MIN, MAX, etc. that allow arguments to be
nonmembers (e.g. text).
SUMIF(range, criterion, [sum range]) » Examples:
SUMIF(A2:A5, “>160”) ⋄ AVERAGEA, COUNTA, MINA, MAXA, etc.
adds values from A2:A5 if they are greater than 160

SUMIF(A2:A5, “>160”, B2:B5)


adds values from B2:B5 if value in A2:A5 on same row is greater than 160.

AVERAGEIF(range, criterion, [average range])


AVERAGEIF(A2:A5, “>160”)
average values from A2:A5 if they are greater than 160

AVERAGEIF(A2:A5, “>160”, B2:B5)


average values from B2:B5 if value in A2:A5 on same row is greater than 160.

145 146

“_A” Functions MIS – Spreadsheets– MS Excel


» Variant of functions like AVERAGE, COUNT, MIN, MAX, etc. that allow arguments to be
nonmembers (e.g. text). Built-in Functions - Payments ( PMT )
» Examples: Calculates the payment of a loan based on constant payments and
⋄ AVERAGEA, COUNTA, MINA, MAXA, etc. a constant interest rate

=PMT(rate,nper,pv,fv,type)
rate – interest rate
nper – total # of payments
pv- present value (principal)
fv – future value, default =0
Ignores text
type - indicates when payment is due
0 – (default) at end of the period
1 – at the beginning of the period
Treats text
as 0s
147 148
MIS – Spreadsheets– MS Excel MIS – Spreadsheets– MS Excel

Built-in Functions - Payments ( PMT ) Built-in Functions - Payments ( PMT )

Calculates the payment of a loan based on constant payments and =PMT(rate,nper,pv,fv,type)


a constant interest rate rate – interest rate
(annual rate divided by number of annual payments)
=PMT(rate,nper,pv,fv,type) nper – total # of payments
( total number of all payments for the loan duration )
rate – interest rate
pv- present value (principal)
nper – total # of payments ( total amount of the loan )
pv- present value (principal) fv – future value, default =0
( appreciation of assets - IGNORE - always zero (0))
fv – future value, default =0 type - indicates when payment is due
type - indicates when payment is due 0 – (default) at end of the period
0 – (default) at end of the period 1 – at the beginning of the period
1 – at the beginning of the period

149 150

Look Up Functions Look Up Functions


VLOOKUP VLOOKUP
Looks up a value in a ‘table area’ & returns a related value Searches for a value in the leftmost column of a ‘table area’

Requires three arguments: Returns a value in the same row from a column you specify
- numeric value (or cell) to look up to the right of the column containing the value found.
- range of the table
- column number containing the value to return Use VLOOKUP when your comparison values are located
- mode / range_lookup (optional - default value) in a column to the left of the data you want to find.

note: ‘table area’ refers to a subset of a worksheet


that the user delineates using a range
( i.e. C5:G20 )

151 152
Look Up Functions Look Up Functions
VLOOKUP Example 11:
=VLOOKUP(value, table, offset, mode)
value is the item you are looking for Find Linda’s location
table is the lookup table
offset is the position of the column within
the table with the related value

The mode controls the type of search


- False – an exact match search
- True – an approximate match search (default)

153 154

Look Up Functions Look Up Functions


Example 11: Example 11:

Find Linda’s location Find Linda’s location

=VLOOKUP(“Linda”, D4:F9, 3 , FALSE)

- look at the column with the names - look at the column with the names
- find Linda’s - find Linda’s
- move across two columns to find her location is ‘Sudbury’ - move across two columns to find her location is ‘Sudbury’

155 156
Look Up Functions Look Up Functions
Example 11: Example 11:
=VLOOKUP(“Linda”, D4:F9, 3 , FALSE) =VLOOKUP(“Linda”, D4:F9, 3 , FALSE)

“Linda” – information we want to “Linda” – information we want to


find in the 1st column find in the 1st column
D4:F9 – specifies the ‘table area’ D4:F9 – specifies the ‘table area’
to look in to look in
3 – column number inside our 3 – column number inside our
‘table area’ where the information ‘table area’ where the information
we want (ie. Location) we want (ie. Location)
FALSE – specifies want an exact FALSE – specifies want an exact
match to the first parameter match to the first parameter

157 158

Look Up Functions Look Up Functions


Example 11: Example 11:
=VLOOKUP(“Linda”, D4:F9, 3 , FALSE) =VLOOKUP(“Linda”, D4:F9, 3 , FALSE)

“Linda” – information we want to “Linda” – information we want to


find in the 1st column find in the 1st column

D4:F9 – specifies the ‘table area’ D4:F9 – specifies the ‘table area’
to look in to look in

3 – column number inside our 3 – column number inside our


‘table area’ where the info ‘table area’ where the information
1 2 3 we want (ie. Location) we want (ie. Location)

FALSE – specifies want an exact FALSE – specifies want an exact


match to the first parameter match to the first
parameter
159 160
Look Up Functions Look Up Functions
HLOOKUP HLOOKUP

Looks up a value in a ‘table area’ & returns a related Searches for a value in the uppermost row of a table
value
Returns a value in the same column from a row you specify
Requires three arguments: below the row containing the value found.
- numeric value (or cell) to look up
- range of the table Use HLOOKUP when your comparison values are located
- row number containing the value to return in a row below the data you want to find.
- mode / range_lookup (optional - default value)

161 162

Look Up Functions Look Up Functions


HLOOKUP Example 12:
=HLOOKUP(value, table, offset, mode)
Find Wrangler’s
value is the item you are looking for
table is the lookup table
MPG rating
offset is the position of the row within
the table with the related value

The mode controls the type of search


- False – an exact match search
- True – an approximate match search (default)
163 164
Look Up Functions Look Up Functions
Example 12: Example 12:

Find Wrangler’s Find Wrangler’s


MPG rating MPG rating

=HLOOKUP(“Wrangler”, C3:F6, 3 , FALSE)


- look at the row with the Model names - look at the row with the Model names
- find Wrangler - find Wrangler
- move down two row to find the MPG rating is 16 - move down two row to find the MPG rating is 16

165 166

Look Up Functions Look Up Functions


Example 12: Example 12:
=HLOOKUP(“Wrangler”, C3:F6, 3 , FALSE) =HLOOKUP(“Wrangler”, C3:F6, 3 , FALSE)

“Wrangler” – information we want “Wrangler” – information we want


to find in the 1st row to find in the 1st row

C3:F6 – specifies the ‘table area’ C3:F6 – specifies the ‘table area’
to look in to look in

3 – row number inside our 3 – row number inside our


‘table area’ where the information ‘table area’ where the information
we want (ie. MPG) we want (ie. MPG)

FALSE – specifies want an exact FALSE – specifies want an exact


match to the first parameter match to the first parameter

167 168
Look Up Functions Look Up Functions
Example 12: Example 12:
=HLOOKUP(“Wrangler”, C3:F6, 3 , FALSE) =HLOOKUP(“Wrangler”, C3:F6, 3 , FALSE)

“Wrangler” – information we want “Wrangler” – information we want


to find in the 1st row to find in the 1st row
1
2 C3:F6 – specifies the ‘table area’ C3:F6 – specifies the ‘table area’
3 to look in to look in
4

3 – row number inside our 3 – row number inside our


‘table area’ where the info ‘table area’ where the information
we want (ie. MPG) we want (ie. MPG)

FALSE – specifies want an exact FALSE – specifies want an exact


match to the first parameter match to the first
parameter

169 170

Look Up Functions Look Up Functions


TASK: Find Torque where MPG rating is approximately 18
Example 12:
=HLOOKUP(18, C5:F6, 2 , TRUE)
=HLOOKUP(E3, C3:F6, 3 , FALSE)
TRUE– specifies want an APPROXIMATE
E3 – information we want (Wrangler) match to the first parameter
to find in the 1st row TRUE– “PRICE IS RIGHT”
C3:F6 – specifies the ‘table area’ - closet without going over
to look in
- 18 is greater than 16,
3 – row number inside our but less than 20
‘table area’ where the information
we want (ie. MPG) - return the value before
going over
FALSE – specifies want an exact
match to the first parameter
check: if number is less - go on, if greater then go back to previous number

171 172
Referencing Multiple Worksheets Referencing Multiple Worksheets

Use the value in a cell on one worksheet on a different cell Use the value in a cell on one worksheet on a different cell
in another worksheet. in another worksheet.

cell reference (syntax) cell reference (syntax)


worksheet_name!cell_reference worksheet_name!cell_reference

example: example:
=Sheet2!E3 =IF(PayScale!E3>25,C10,Sheet2!F9)

173 174

More Useful Functions


Function(s) Description
LARGE, SMALL Returns the kth, smallest (SMALL) or largest (LARGE) value in the range.
SQRT Find the square root of a number.
RANK Returns the rank of a number in a list of numbers.
PERCENTILE Returns the k-th percentile of values in a range.
PV, FV Present (PV) and future (FV) value functions (finance).
ROW, COLUMN Current row (ROW) or column (COLUMN) if no arguments are given. Gives row or
column of a cell if cell reference given.
ABS Returns the absolute value of a number. The absolute value of a number is the
number without its sign.
MEDIAN Returns the median of the given numbers. The median is the number in the middle of
a set of numbers.

Find more functions in: The List of Excel Functions

175

You might also like