01.Class 1+2 Excel Formulas
01.Class 1+2 Excel Formulas
WELCOME TO
AUDITING TOOLS:
Trace Precedents/Dependents shows
which cells affect or are affected by the
value of the selected cell
2
F o r m ul a S y n t ax
A1 A1:C4 A1,C4
Single-cell references describe a Array references describe a Non-contiguous references
cell’s location within a worksheet, in contiguous group of cells based describe selections of individual
terms of the intersection between a on the location of the top-left (A1) cells that do not share a common
column (A through XFD), and a row and the bottom-right (C4) cells, border, separated by a “,”
(1 through 1,048,576) separated by a “:”
3
R e f e r e nc e T y p es
Hold the phone, how come some cell references include a “$”?
These are used to create Fixed, Relative, or Mixed References; the $ basically locks a
specific cell range or reference so that it does not change if you apply the formula to othercells
For Example:
$A$1 = Fixed column, Fixed row
A$1 = Relative column, Fixed row
$A1 = Fixed column, Relative row
A1 = Relative column, Relative row
PRO TIP:
Select part of your formula with the
cursor and use “F4” to quickly scroll
through reference types. ALWAYS
THINK ABOUT YOUR REFERENCES
4
C o m m on E x c el E r r o rs
Column isn’t wide enough to display values Drag or double-click column border to increase width, or right-
###### click to set custom column width
Make sure that function names are correct, references are valid
#NAME? Excel does not recognize text in a formula
and spelled properly, and quotation marks and colons are in place
Make sure that you didn’t move, delete, or replace cells that are
#REF! Formula refers to a cell that it notvalid
referenced in your formula
5
I F E R RO R S t a t e m e nt
=IFERROR(value, value_if_error)
Formula or value (which may or may not result in an error) Value returned in the case of an error
PRO TIP:
If you’re writing a formula that may trigger an error (i.e. a VLOOKUP where not all values
have a match), WRITE THE FULL FORMULA FIRST then wrap it in an IFERROR statement
6
F u n c t i on S h o r t c u ts
The F2 function displays the cell ranges that are tied to a given formula
PRO TIP:
Use F2 to help diagnose formula errors or make
quick adjustments to cell references and arrays
7
CTRL S h o r t c u ts
The CTRL function can be combined with a variety of keys, such as:
1) CTRL- ARROW
Jumps to the left, right, top, or bottom edge CTRL-SHIFT-RIGHT ARROW
(i.e. last non-blank cell) of a contiguous data array
2) CTRL-SHIFT-ARROW
Extends a selection to the left, right, top, or bottom CTRL-SHIFT-DOWN ARROW
3) CTRL-PAGE UP/DOWN
Jumps between tabs of a workbook
8
A LT Key T i ps
The ALT function enables Key Tips, which allow you to access any function in
the ribbon using keyboard shortcuts (Note: you do not need to hold down ALT)
9
Data Validation
Data Validation allows you to specify exactly what types of values a cell can contain
(i.e. whole numbers, positive integers, values from a list, etc.)
(but the best part is that you can write your own
hilarious error messages) See, Excel can be fun!
10
Fixed vs. V o l a t il e F u n c t i o ns
Volatile Functions are functions or formulas in Excel that change every time the
workbook recalculates (i.e. any time you enter data anywhere in any open workbook)
PRO TIP:
To control when Excel recalculates, change the Calculation Options
to “Manual” in the Formulas tab (just don’t forget you changed it!)
11
L o g i cal O p e r a t or s - I n t ro
12
IF S t a t e m e n ts
Any test that results in either Value returned if logical Value returned if logical
TRUE or FALSE test is TRUE test is FALSE
(i.e. A1=“Google”, B2<100, etc)
= IF(B2<=0,“Yes”,”No”)
In this case we’re categorizing the Freeze column
as “Yes” if the temperature is equal to or below 32,
otherwise “No”
13
N e s ted IF S t a t e m e n ts
= IF(B2<40,”COLD”,IF(B2>80,”HOT”,”MILD”))
14
AND/OR S t a t e m e n ts
Excel’s AND and OR statements allow you to include multiple logical tests at once:
=IF(OR(F2=“Rain”,F2=“Snow”),“Wet",“Dry")
Here we’re categorizing conditions as “Wet” if the
precipitation type equals “rain” OR “snow”,
otherwise Conditions = “Dry”
=IF(AND(D2=“Yes”,C2>0),“Snow",IF(AND(D2=“No”,C2>0),“Rain",“None"))
If the temp is below freezing AND the amount of precipitation > 0, then Precip Type = “Snow”, if the temp is
above freezing AND the amount of precipitation >0, then Precip Type = “Rain”, otherwise Precip Type = “None”
PRO TIP:
When writing nested functions, copy/paste repetitive pieces and tweak
individual elements to save time (rather than starting from scratch)
15
N O T / <> O p e r a t o rs
If you want to evaluate a case where a logical statement is not true, you can use
either the NOT statement or a “<>” operator
=IF(NOT(C2=0),“Wet",“Dry")
=IF(C2<>0,“Wet",“Dry")
In both of these examples, we’re defining Conditions = “Wet” if the amount of precipitation is NOT equal to 0
16
I F E R R OR
=IFERROR(value, value_if_error)
PRO TIP:
If you’re writing a formula that may trigger an error (i.e. a VLOOKUP where not all values
have a match), WRITE THE FULL FORMULA FIRST then wrap it in an IFERROR statement
17
IS S t a t e m e n ts
18
Basic Stats F u n c t i o ns
=COUNT(A2:A20)
=AVERAGE(A2:A20)
=MEDIAN(A2:A20)
=MODE(A2:A20)
=MAX(A2:A20)
=MIN(A2:A20)
=PERCENTILE(A2:A20,.25)
=PERCENTILE(A2:A20,.75)
=STDEV(A2:A20)
=VAR(A2:A20)
19
RANK/SMALL/LARGE
RANK(A2,A2:A8) = 2
RANK(A3,A2:A8) = 7 (lowest)
The RANK function returns the rank of a
RANK(A4,A2:A8) = 6
particular number among a list of values
RANK(A5,A2:A8) = 1 (highest)
RANK(A6,A2:A8) = 4
RANK(A7,A2:A8) = 3
RANK(A8,A2:A8) = 5
LARGE(A2:A8,2) = 90
(the 2nd largest number in the
The SMALL/LARGE functions return the array is 90)
20
PERCENTRANK
=PERCENTRANK(array, x)
21
RAND/RANDBETWEEN
=RANDBETWEEN(0,100)
22
S U M P R O D U CT
23
S U M P R O D U CT
PRO TIP:
When you add filters to a SUMPRODUCT,
you need to change the commas to
multiplication signs
24
S U M P R O D U CT
25
COUNTIF/SUMIF/AVERAGEIF
The COUNTIF, SUMIF, and AVERAGEIF formulas calculate a sum, count, or average
based on specific criteria
=COUNTIF(range, criteria)
=SUMIF(range, criteria, sum_range)
=AVERAGEIF(range, criteria, average_range)
Which cells need to Under what condition Where are the values
match your criteria? do I want to sum, count, that I want to sum
or aver age? or average?
COUNTIF(B2:B20,22) = 2
SUMIF(A2:A20,“Ryan”,B2:B20) = 190
SUMIF(A2:A20,“<>Tim”,B2:B20) = 702
AVERAGEIF(A2:A20,“Maria”,B2:B20) = 45.75
26
COUNTIFS/SUMIFS/A VERAGEIFS
COUNTIFS, SUMIFS, and AVERAGEIFS are used when you want to evaluate a
count, sum, or average based on multiple conditions or criteria
=COUNTIFS(criteria_range1, criteria1, criteria_range2 , criteria2…)
=SUMIFS(sum_range, criteria_range1, criteria1, criteria_range2 , criteria2…)
=AVERAGEIFS(average_range, criteria_range1, criteria1, criteria_range2 ,
criteria2…)
COUNTIFS(B2:B13,“Search”, D2:D13,“>200”) =
3 SUMIFS(D2:D13,
A2:A13,“Feb”,B2:B13,“Display”) = 734
AVERAGEIFS(D2:D13,
A2:A13,“Jan”,C2:C13,“MSN”) = 263
PRO TIP:
Ifyou use <or >,you need to add quotation
marks as you would with text (i.e. “>200”)
27
N a m ed R a n g es
Using Named Arrays can simplify a lookup function if you use the same
data array in multiple formulas
=VLOOKUP(A1,$A$1:$D$6,2)
=VLOOKUP(A1,Apparel,2)
28
V L O O K UP
Let’s take a look at one of Excel’s most common reference functions – VLOOKUP:
This is the value that This is where you Which column Are you trying to match the
you are trying to match are looking for the contains the data exact lookup value (0), or
in the table array lookup value you’re looking for? something similar (1)?
D2=VLOOKUP(A2, $G$1:$H$5, 2, 0)
29
H L O O K UP
Use HLOOKUP if your table array is transposed (variables headers listed in rows)
This is the value that This is where you Which column Are you trying to match the
you are trying to match are looking for the contains the data exact lookup value (0), or
in the table array lookup value you’re looking for? something similar (1)?
D2=HLOOKUP(A2, $H$1:$L$2, 2, 0)
With an HLOOKUP, we search for the product name
in H1:L2 and return the value from the 2nd row down
30
Laws of L o o k u ps
There are two key rules that constrain VLOOKUP and HLOOKUP formulas:
2. Excel will always return the value from the top most
row or left most column of a table array when
multiple instances of the lookup value are present
PRO TIP:
Avoid breaking Law #2 by identifying a “Key”
that is common to both datasets and is unique
for every row (NOTE: Keys often take the form
of a concatenation of multiple fields)
31
R O W / R O WS
The ROW function returns the row number of a given reference, while the ROWS
function returns the number of rows in a given array or array formula
=ROW([reference])
=ROWS(array)
ROW(C10) = 10
This example uses an array, which is why
it includes the fancy { } signs – more on ROWS(A10:D15) = 6
that in the ARRAY functions section
ROWS({1,2,3;4,5,6}) = 2
32
COLUMN/COLUMNS
The COLUMN function returns the column number of a given reference, while the
COLUMNS function returns the number of columns in a given array or array formula
=COLUMN([reference])
=COLUMNS(array)
33
I N D EX
The INDEX function returns the value of a specific cell within an array
What range of cells How many rows down How many columns over
are you looking at? is the value you want? is the value you want?
INDEX($A$1:$C$5, 5, 3) = 234
34
M A T CH
The MATCH function returns the position of a specific value within a column or row
What value are you trying In which row or column are Are you looking for the exact value
to find the position of? you looking? (must be a 1- (0), or anything close?
dimensional array)
1: Find largest value < or = lookup_value
0: Find exact lookup_value
-1: Find smallest value > or = lookup_value
MATCH(“Pliers”,$A$1:$A$5, 0) = 4
MATCH(66,$A$3:$C$3, 0) = 3
Matching the word “Pliers” in column A, we
find it in the 4th row. Matching the number 66
in row 3, we find it in the 3rd column
35
INDEX/MATCH
INDEX and MATCH are commonly used in tandem to act like a LOOKUP function; the
only difference is that INDEX/MATCH can find values in any column or row in an array
Example: Price Checker In this example, we want to populate the price of a given product and
size in cell B10 by returning a particular value within the array B2:D4
Considering the output of each MATCH function, the formula is just a simple INDEX:
36
O F F S ET
The OFFSET function is similar to INDEX, but can return either the value of a cell
within an array (like INDEX) or a specific range of cells
What’s your How many rows How many If you want to return a
starting point? down should you columns over multidimensional array, how
move? should you move? tall and wide should it be?
37
TRIM/UPPER/LOWER/PROPER
Text functions can be used to standardize formatting, particularly the TRIM, UPPER,
LOWER, and PROPER functions:
PRO TIP:
If two text strings are identical except one has a trailing space, they will look exactly the same
but Excel will treat them as completely different values; TRIM will make them equivalent
38
CONCATENATE
CONCATENATE allows you to combine text, cell values, or formula outputs into a
single text string
Note: Rather than typing “=CONCATENATE(Text1, Text2…)”, you can simply
separate each piece of the resulting text string with an ampersand (“&”)
39
LEFT/MID/RIGHT/LEN
The LEFT, MID, and RIGHT functions return a specific number of characters from
a location within a text string, and LEN returns the total number of characters
=LEFT(text, [num_chars])
=RIGHT(text, [num_chars])
=MID(text, start_num, num_chars)
40
TEXT/VALUE
The TEXT function converts a numeric value to text and assigns a particular format
=TEXT(value, format_text)
Numeric value, formula that evaluates to a numeric Numeric format as a text string enclosed in
value, or reference to a cell containing a numeric value quotes (i.e. “m/d/yyyy”, “$0.00” or “#,##0.00”
PRO TIP:
Use VALUE to convert a text string that
represents a number into a value
41
SEARCH/FIND
The SEARCH function returns the number of the character at which a specific
character or text string is first found (otherwise returns #VALUE! error)
What character or string Where is the text that Search from the beginning (default) or
are you searching for? you’re searching through? after a certain number of characters?
PRO TIP:
The FIND function works exactly the same way, but is case-sensitive
42
IF(ISNUMBER(SEARCH
=IF(ISNUMBER(SEARCH(“Disp”,A2)),”Display”,”Other”)
Search the cells in column A for the text string “Disp” and
classify column B as “Display” if you find it, “Other” if you don’t
43
Date V a l ue
Every date in Excel has an associated date value, which is how Excel
calculates the passage of time (using midnight on 1/1/1900 as the starting point)
Excel recognizes most typed dates and automatically applies a common format
(i.e. m/d/yyyy), along with an associated date value (cell format → General)
Note: If you type a date in a format that Excel does NOT recognize, it will be treated as textand
there will be no associated date value; however, you can use a DATEVALUE or TIMEVALUE
function to convert unformatted dates or times into serialvalues
Jan 1,1900 is the first date with an assigned date value (1). Feb 6,
2015 is the 42,041st day since 1/1/1900, so its date value = 42041
44
Date Formatting
To format dates in Excel, you can either select a preset option from the “Date”
category of the “Format Cells” dialog box, OR create your own custom format
Preset Formats: Custom Format: You can build your own custom
formats using combinations of
date/time codes. For example:
45
Fill S e r i es
When you drag the corner of a cell containing a date, Excel automatically
applies subsequent values automatically using Fill Series options:
Fill Weekdays = Increases the date by 1 day per cell (excluding weekends)
46
TODAY()/NOW()
The TODAY() and NOW() functions return the current date or exact time
Note: These are volatile functions, meaning that they change with every worksheet calculation
PRO TIP:
Make sure to enter TODAY() and NOW() functions with both
parentheses included – these functions don’t refer to other cells
47
Serialization F o r m u l as
Excel will always calculate dates and times based on their precise underlying serial
values, but what if you need to work with less-specific values, like months instead of
days, or hours instead of seconds?
The YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND functions extract individual
components of a given date:
48
E O M O N TH
Use the EOMONTH function to calculate the last day of a given month, or to
calculate the start/end dates of previous or future months
=EOMONTH(start_date, months)
Reference to the cell containing Number of months before or after the start/current date (positive number
the start/current date yields a date in the future, negative number yields a date in the past
=EOMONTH(C2, 0)
=EOMONTH(C2, -1)+1
=EOMONTH(C2, 0)+1
49
Y E A R F R AC
YEARFRAC calculates the fraction of a year represented by the number of whole days
between two dates
50
W E E K D AY
If you want to know which day of the week a given date falls on, there are two
ways to do it:
1) Use a custom cell format of either “ddd” (Sat) or “dddd” (Saturday)
-Note that this doesn’t change the underlying value, only how that value is displayed
2)Use the WEEKDAY function to return a serial value corresponding to a particular
day of the week (either 1-7 or 0-6)
51
WORKDAY/NETWORKDAYS
WORKDAY returns a date that is a specified number of days before or after a given start
date, excluding weekends and (optionally) holidays; NETWORKDAYS counts the
number of workdays between two dates:
52
D A T E D IF
DATEDIF calculates the number of days, months, or years between two dates
Reference to the cell Reference to the cell How do you want to calculate the difference?
containing the start date containing the end date “D” = # of days between dates
“M” = # of months between dates
“Y” = # of years between dates
PRO TIP:
If you only need to calculate the # of days between dates, just use subtraction
53
F o r m u l a - B a se d Formatting
54
Formula-Based Formatting
55
Array F u n c t i on s - I n t ro
Array functions perform multiple calculations on one or more items in an array, and
can take the form of either a single-cell formula (which exists within one cell) or a multi-
cell formula (which can be applied to a number of cells and return multiple results)
You must press CTRL-SHIFT-ENTER to enter, edit, or delete an array formula; this
automatically adds brackets “{ }” to indicate that the function applies to an array
If you select D2:D5, type “=B2:B5*C2:C5” and hit If you select D2:D5, type “=B2:B5 * C2:C5” and
ENTER, the formula will only be applied to cell D2 hit CTRL-SHIFT-ENTER, you have created an
array formula applied to all cells in the range
56
Array Functions - R u l es
When you work with array functions, you must obey the following rules:
57
PROS & C O NS
Array functions can be incredibly powerful, but also a total buzzkill to work with;
here are some of the key pros and cons of using them:
PROS CONS
-Condenses multiple calculations into one -Can be very difficult to modify or delete
formula, often reducing file size existing array formulas
-Can perform some complex functions that -Limited visibility into the formula’s function,
non-array formulas cannot especially for users who are not familiar with
arrays
-Reduces the risk of human error such as
accidentally deleting parts of arrays or -Eliminates the option to modify cells
mistyping formulas contained within arrays
58
Ar ray C o n s t a n ts
Array constants are created by manually entering a list of items directly into the
formula bar and manually surrounding the list with brackets ({ })
59
Array C o n s t a nt s in F o r m u l as
Array constants can contain values, text (surrounded by “ ”), logical values (TRUE,
FALSE), or error values (#N/A), and can be used as part of an array formula
PRO TIP:
You manually add the brackets when you type array
constants, but the additional brackets surrounding the entire
formula are automatically added once you press C-S-E
60
Named A r r a ys
Just like normal cell ranges, array constants can be assigned a name using Excel’s
name manager, which can make them much easier to work with
Select “Define Name” (or Name Manager → New) from the Formulas tab
61
T R A N S P O SE
The TRANSPOSE function allows you to change the orientation of a given data array
(i.e. from 5 rows x 2 columns to 2 rows x 5 columns)
NOTE: The range in which you enter a TRANSPOSE function must be the exact
dimensions of the transposed data
{=TRANSPOSE(array)}
PRO TIP:
To transpose a data set that you may want to later
edit, just use Paste Special → Transpose (ALT-H-V-T)
62
I N D I R E CT
The INDIRECT function returns the reference specified by a text string, and can be
used to change a cell reference within a formula without changing the formula itself
=INDIRECT(ref_text, [a1])
Which cell includes the text Is your text string in A1 format (1) or R1C1 format (0)?
that you are evaluating?
63
I N D I R EC T ( c o n t)
Let’s be real, the INDIRECT function is pretty confusing at first. Here are a few more
examples that should give you a sense of how it works and why it can be useful:
SUM(D2) = 0
SUM(INDIRECT(D2)) = 16
The sum of “B3:B5” as a value doesn’t make sense, but the sum of
B3:B5 as a reference is valid – INDIRECT tells Excel to recognize
that the cell you’re referring to is a reference, not a value
64
H Y P E R L I NK
=HYPERLINK(link_location,[friendly_name])
Where will people go if they click? How do you want the link to read?
=HYPERLINK("#Sheet2!A1”)
PRO TIP:
Use =HYPERLINK("#'"&A2&"'!A1") to jump to
cell A1 of the sheet name specified in A2 (note
the extra single quotation marks!)
65