Data Analytics
Referencing and Lookups
WELCOME TO GA
GENERAL ASSEMBLY
Our Learning Goals
● Build relationships between cells in Excel.
● Manipulate data sets using VLOOKUP.
● Look up values in other tables/sheets using
INDEX and MATCH.
2 | © 2023 General Assembly
Where We Are in the DA Workflow
Wrangle/Prepare:
Clean and prepare
relevant data.
Analyze: Structure,
comprehend, and
visualize data.
3 | © 2023 General Assembly
Discussion:
Looking Up Information
Referencing is all about looking something up elsewhere and comparing it with
what’s in front of you.
While we’re still investigating the reason behind the increase in returns, let’s
open up all of your Superstore files and look into those attributes you think will
have the biggest impact on returns.
4 | © 2023 General Assembly
Discussion:
Referencing Information
Based on the attributes we identified, we now know that we need to:
Reference customers with frequent returns in a region and match them up
with attributes of their sale.
What’s an efficient way to go about this?
5 | © 2023 General Assembly
Referencing and Lookups
Getting Started With VLOOKUP
WELCOME TO GA
GENERAL ASSEMBLY
Referencing and VLOOKUP
Referencing, in its basic form,
means pulling the value of one cell
into another cell.
With VLOOKUP, we will sometimes
need to reference across files and
lock references to make the
A2 references A1
formula function properly.
7 | © 2023 General Assembly
Referencing With Advanced Excel Tools
VLOOKUP, HLOOKUP, XLOOKUP, and
INDEX/MATCH are often considered
advanced tools that increase efficiency
while reducing data integrity issues.
8 | © 2023 General Assembly
What Is VLOOKUP?
V stands for “vertical.”
VLOOKUP is:
● A function that works with data
formatted in columns.
● A function that finds or “looks up”
the value in one column of data and
returns the corresponding value
from another column (and usually
another table).
9 | © 2023 General Assembly
Building a VLOOKUP Statement
When building a VLOOKUP statement:
● In the cell, type “=VL.”
● Double click on the function name that’s presented for syntax.
10 | © 2023 General Assembly
Building a VLOOKUP Statement
Alternatively, click fx
in the menu ribbon
and select Function >
VLOOKUP.
11 | © 2023 General Assembly
VLOOKUP Syntax
Lookup_value is the value that will be used
to match data. It’s usually an identifier and it
must exist in both worksheets.
=VLOOKUP(lookup_value, table_array, col_index_num,
[range_lookup])
Col_index_num is the
number of the column from
Table_array is the table from the left side of the
which you want to retrieve data. table_array from which you
want to retrieve data.
12 | © 2023 General Assembly
VLOOKUP Syntax | Range_lookup
=VLOOKUP(lookup_value, table_array, col_index_num,
[range_lookup])
TRUE: Approximate match is
range_lookup defines whether or not the
needed.*
lookup_value is an approximate match or
an exact match of the value you are
comparing it to in the left-most column of FALSE: An exact match is
the table_array. required.
13 | © 2023 General Assembly
In the work of a data analyst, it is rare to have all
the data you need right in your data set.
14 | © 2023 General Assembly
Guided Walk-Through:
Pulling Data From Another Worksheet
Let’s combine data from another worksheet into the Superstore data set and
explore the concept of a “lookup table” as well as how to use one to categorize
our quantitative data.
1. Open your workbook: Lesson 03_Superstore Workbook.
2. In order to combine these two lists, we’ll create a third column
in “Orders” with “Customer Names” — we can use VLOOKUP to “look up”
one value in another table and return another column in that row.
15 | © 2023 General Assembly
15
Guided Walk-Through:
Pulling Data From Another Worksheet (Cont.)
Let’s try simplifying what’s required by naming a range.
1. In cell C2 of “Returns”, enter: =VLOOKUP(A2,orders!A:AA,27,FALSE).
The customer names should populate cell C2.
1. Double click the bottom right corner of the cell — or click/drag — to
replicate this function down the entire column.
16 | © 2023 General Assembly
16
Guided Walk-Through:
Using a VLOOKUP
Now, we’ll examine if certain states have more returns than others.
1. In our “Returns” worksheet, go to Column C.
2. Name this “state” by typing this in Cell C1.
3. In Cell C2, enter:
=VLOOKUP(A2,orders!A:V,23,FALSE)
4. Expand this formula to all rows by double clicking the bottom-right corner
of the cell.
Now we have the states in our “Returns” data set!
17 | © 2023 General Assembly
17
Solo Exercise:
10 minutes
Moving Data With VLOOKUP
Now let’s say we want to bring in more information from the “Orders” data set.
We don’t need everything, just a few columns.
On your own, use VLOOKUP to bring the “category,” “sales,” and “profit”
columns from the “Orders” workbook to the “Returns” workbook.
Remember to start from your “Order_ID” column!
18 | © 2023 General Assembly
18
Solo Exercise:
Moving Data With VLOOKUP — Solutions
Category:
=VLOOKUP(A2,orders!A:J,10,FALSE)
Sales:
=VLOOKUP(A2,orders!A:N,14,FALSE)
Profit:
=VLOOKUP(A2,orders!A:O,15,FALSE)
19 | © 2023 General Assembly
19
Referencing and Lookups
Creating Categorical Variables
WELCOME TO GA
GENERAL ASSEMBLY
What Are Categorical Variables?
A categorical value, aka, a nominal variable, typically has two or more non-
ordinal categories (values).
Hair color is a categorical
variable that has a number of
categories (e.g., blonde, brown,
red...), but there is no inherent
order to these categories.
21 | © 2023 General Assembly
Creating Categorical Values
Often, it’s helpful to create categorical
values from numeric values.
For example, a test that is scored 0–100
could be classified as A, B, C, D, or F,
depending on the score.
22 | © 2023 General Assembly
Discussion:
Categorical Values in the Superstore Data Set
Knowing that it’s helpful to create categorical values from
numeric values, let’s take a look at the “Orders” data.
To help us solve the returns problem, which columns
should we use to create categorical values that will help us
analyze our data?
23 | © 2023 General Assembly
Computers Out:
Categorical Values in the Profit Margins
Let’s practice assigning categorical values to
the profit margins.
1. In the “Returns” workbook, in Cell G1,
type “profit_margin.”
2. In Cell G2, enter the formula “=E2/D2”
and expand.
3. Classify our profit margins as either low,
medium, or high.
24 | © 2023 General Assembly
24
Guided Walk-Through:
Margin Lookup
Refer to the steps below:
1. In your “Returns” workbook, create a new worksheet called “Margin Lookup.”
2. In Cells A1, A2, and A3, enter values -5, 0, and 0.3.
3. In Cells B1, B2, and B3, enter values low, medium, and high.
4. On the original worksheet (in the “Returns” workbook), type “Margin Category” in Cell H1.
5. In H2, complete the lookup:
=VLOOKUP(F2, 'margin_lookup'!$A:$B, 2, TRUE).
6. Expand to all rows.
25 | © 2020 General Assembly
25
Discussion:
VLOOKUP and Absolute Cell References
Remember absolute cell references?
● What happens if we try that last formula
without references?
● Can anyone explain what’s happening to the
formula?
Share your answers with the class!
26 | © 2023 General Assembly
Referencing and Lookups
Other LOOKUPs
WELCOME TO GA
GENERAL ASSEMBLY
What Is HLOOKUP?
H stands for “horizontal.”
HLOOKUP is closely related to VLOOKUP,
but instead of working with data sorted into
columns, HLOOKUP work with data sorted
in rows.
Because this is usually a difficult way to
arrange data, it is not often used.
28 | © 2023 General Assembly
HLOOKUP Syntax
The value to look for in the The table from which to
first column of a table. retrieve a value.
=HLOOKUP(lookup_value, table_array, row_index_num,
[range_lookup])
The row in a table from
which to retrieve a value.
Range_lookup: optional.
TRUE = Approximate match (default).
FALSE = Exact match.
29 | © 2023 General Assembly
Limitations of VLOOKUP/ HLOOKUP
● These LOOKUPs are unidirectional and must work with indicies fixed to
the left side (VLOOKUP) or top (HLOOKUP) of the work area.
● Because the VLOOKUP references a col_index, it’s unable to dynamically
update whenever you insert a column or columns in the table_array.
Let’s see what happens when we “break” the VLOOKUP by inserting a column.
30 | © 2023 General Assembly
Referencing and Lookups
XLOOKUP
WELCOME TO GA
GENERAL ASSEMBLY
What Is XLOOKUP?
XLOOKUP is closely related to the other
LOOKUPs, but it...
● Only requires the lookup_value,
lookup_array, and return_array arguments.
● Does not require the return_array to be to
the right of the lookup_array (it can be on
either side).
● The match_mode argument is optional and
defaults to exact.
32 | © 2023 General Assembly
XLOOKUP Syntax
The value to look for in the Array that contains the
first column of a table. answer you want to return.
=XLOOKUP(lookup_value, lookup_array, return_array)
Array in which the
lookup_value can be found.
33 | © 2023 General Assembly
Guided Walk-Through:
Basic XLOOKUP
XLOOKUP was introduced to a select set of customers in August 2019 and
officially launched to all Office 365* customers in January 2020.
A basic XLOOKUP accepts three arguments:
=XLOOKUP(lookup_value, lookup_array, return_array)
*You will only be able to use XLOOKUP with Office 365.
34 | © 2023 General Assembly
34
Guided Walk-Through:
“If Not Found” XLOOKUP
“If not found” XLOOKUP allows us to set a return value if a match isn’t found,
negating the use of “IFERROR” or “IFNA.”
“If not found” XLOOKUP accepts four arguments:
=XLOOKUP(lookup_value, lookup_array, return_array, value_if_not_found) .
35 | © 2023 General Assembly
35
Guided Walk-Through:
XLOOKUP Search Mode
XLOOKUP Search Mode allows us to specify the direction of the lookup.
=XLOOKUP(lookup_value, lookup_array, return_array, value_if_not_found,
match_mode, search_mode) .
● Match_mode specifies exact or inexact match.
● Search_mode specifies the direction of the lookup: 1 is first item to last and
-1 is last item to first.
36 | © 2023 General Assembly
36
Referencing and Lookups
INDEX and MATCH
WELCOME TO GA
GENERAL ASSEMBLY
INDEX
38 | © 2023 General Assembly
MATCH
39 | © 2023 General Assembly
INDEX/ MATCH LOOKUP
40 | © 2023 General Assembly
Referencing and Lookups
Wrapping Up
WELCOME TO GA
GENERAL ASSEMBLY
Recap Looking Ahead
Today, we...
Up Next: Aggregating Data With
● Built relationships between PivotTables
cells in Excel.
● Manipulated data sets using
VLOOKUP.
● Looked up values in other
tables using INDEX and
MATCH.
42 | © 2023 General Assembly
Additional Resources
● Excel Keyboard Shortcuts
● Relative, Absolute, and Mixed Cell References
● How to Use INDEX MATCH
● Using INDEX MATCH
● F4 No Longer Changes Absolute Cell References
● Explaining XLOOKUP
● VLOOKUP vs. INDEX MATCH
43 | © 2023 General Assembly