Menu

Lookups and Pivot Tables

Lesson 5: Lookups and Pivot Tables

Why connect and summarise data?

Tool

Purpose

Analogy

LookupBrings a value from a related tableLike a SQL join for one column
Pivot tableGroups and aggregates recordsLike SQL GROUP BY

Together, they turn detailed transactions into useful summaries without manual copying.

Lookup example

Orders table: OrderID, ProductID, Quantity Products table: ProductID, ProductName, Category

To bring Category into the orders table:

Function

Formula

Notes

XLOOKUP (Excel 365/2021+, Google Sheets)=XLOOKUP(B2, Products!A:A, Products!C:C, "Not found")Flexible, exact match by default, handles "not found"
VLOOKUP (all versions)=VLOOKUP(B2, Products!A:C, 3, FALSE)Key must be in the first column; use FALSE for exact match
INDEX + MATCH=INDEX(Products!C:C, MATCH(B2, Products!A:A, 0))Works in older versions; key can be in any column

The lookup only works if the identifier matches exactly, including data type and spaces.

Pivot table example

Pivot area

Field

Result

RowsRegionOne row per region
ColumnsMonthOne column per month
ValuesSum of RevenueTotal revenue per region per month
FiltersProduct CategoryFocus on one category at a time

Check: the Values area should use SUM for total revenue. Pivot tables sometimes default to COUNT when a column contains text or blanks.

Useful pivot features:

  • Show values as % of total – each region's share of revenue
  • Group dates – by month, quarter, or year
  • Slicers – clickable filters for reports

How it works

  • A lookup relies on a matching key.
  • A pivot table groups rows by selected fields and aggregates a measure.
  • Pivot tables don't update automatically. Refresh them after the source data changes.

Common mistakes

Mistake

Result

Fix

Duplicate keys in the lookup tableReturns only the first matchCheck uniqueness with COUNTIF
Approximate match in VLOOKUPWrong values returned silentlyUse FALSE or XLOOKUP
Key stored as text in one table, number in the other#N/A errorsMake data types consistent
Pivot not refreshedOutdated summaryRefresh after every data update
Source range too smallNew rows excludedUse a formal table as the source

Pivot tables can hide detail, so keep the source data and spot-check a few totals against the original records.


Data Analytics Tutorial



Learn via Video Course

Data Analysis and Processing with Python using Pandas - Data Science Course Logo

Data Analysis and Processing with Python using Pandas - Data Science Course

5 hrs



Get in Touch For Details