Connect Excel Tables With Relationships (Data Model)

Instead of adding VLOOKUP columns to bring region or category into a sales table, connect the tables with a relationship. A PivotTable can then use fields from all of them at once, with no extra formulas.

WhereData → Relationships
PivotTableUse this workbook's Data Model
Works inExcel 2013 and later for Windows

Video

The problem

Sales_Data has the city of each sale, but not its region or country. Those are in another table, Place. A manager wants total sales in South India.

Sales data table with a location column

The usual fix, VLOOKUP columns for region and country, means 100 extra formulas for 50 rows, and more for every new question. A relationship needs none.

What you need

  • Both ranges must be Excel Tables (Ctrl + T). Give them clear names on the Table Design tab.
  • A column with matching values in each, here Location in Sales_Data and City in Place.
  • In the lookup table (Place), each city must appear only once.
Matching city columns in both tables

Step 1: Create the relationship

  1. Data → Relationships → New.
  2. Table: Sales_Data, Column (Foreign): Location.
  3. Related Table: Place, Related Column (Primary): City. Click OK.
Create Relationship dialog
Tables and columns selected for the relationship
Relationship listed in Manage Relationships

Step 2: Build the PivotTable

Insert → PivotTable → From Data Model (in older versions, tick Use this workbook's Data Model). Both tables appear in the field list.

Create PivotTable using the Data Model
Field list showing both tables

Drag Region and Country (from Place) to Rows and Amount (from Sales_Data) to Values. South India: ₹7,40,260.

Sales by region and country from related tables

Add more tables

For units sold by product category, relate Sales_Data[Item] to Product[Product] the same way. One PivotTable can now use fields from all three tables.

Relationship between sales and product tables
PivotTable using fields from three tables

To see all relationships as a diagram, open Data → Manage Data Model (Power Pivot) → Diagram View.

Diagram view of the relationships in Power Pivot

Things to know

  • If the PivotTable shows the same total on every row, the relationship is missing or the fields come from the wrong tables.
  • Excel can't relate tables when the lookup column has duplicates or blanks.
  • For a single extra column, an XLOOKUP is still simpler. Relationships pay off with several lookup tables or large data.
  • Excel for Mac supports the Data Model in Microsoft 365, but not all Power Pivot features.

Related