Build one PivotTable from two related tables
More from PivotTables7 minPremium
Builds on Count, average and show percentages in a PivotTable.
A sales operations analyst in Phoenix keeps orders in one table and customers in another. The VP wants sales by customer segment, and the orders table has only a customer ID, so every month someone adds a lookup column before building the report.
How it works
The Data Model lets one PivotTable use several tables at once, joined by a relationship on a column they share, such as CustomerID. The orders table needs no lookup column.
- Make each list an Excel table and name it, such as Orders and Customers.
- Choose Data > Relationships > New. Set Table to Orders and Column (Foreign) to CustomerID, then Related Table to Customers and Related Column (Primary) to CustomerID, and click OK. The related column must list each customer once.
- Click in the Orders table, choose Insert > PivotTable and check Add this data to the Data Model.
- In the PivotTable Fields pane, click All to see both tables. Drag Segment from Customers to Rows and Amount from Orders to Values.
A PivotTable built on the Data Model also offers Distinct Count in Value Field Settings, which counts each customer once however many orders they placed.
Example
A few rows of the analyst's two tables show what the relationship does.
- Step 1: Order 9001 carries CustomerID C-104.
- Step 2: The relationship finds C-104 in Customers, where it's listed once, with the segment Hospitality.
- Step 3: Order 9004 is C-104 too, so Hospitality adds up $1,250 and $760, $2,010.
Common mistakes
- The relationship the wrong way round. The related table is the one that lists each ID once, here Customers.
- Add this data to the Data Model left unchecked. The PivotTable then sees the Orders table only.
- IDs that don't match exactly, such as C-104 and C104, or numbers stored as text in one table. Orders without a match land under (blank).
In short
- The Data Model lets one PivotTable read several tables, joined on a column they share.
- Make the tables, relate them in Data > Relationships, and build the PivotTable with Add this data to the Data Model.
- It's in Excel for Windows. On a Mac, bring the field over with XLOOKUP instead.
Practice
Premium3 exercises: 1 dialog, 1 set of steps and 1 quiz question.
Practice is part of Premium
Every lesson is free to read, and you can practice the free lessons without an account. This lesson's exercises are part of Premium, which you add to a free account.
Have one? Sign in