Excel’s Data Model lets you link multiple tables into a single query, enforce referential integrity, and automate reports—but creating relationships can be confusing if you don’t follow the right steps. Unlike manual joins, relationships automatically update when source data changes. Here’s how to do it correctly, step by step, with common pitfalls and fixes.
What You'll Need
- Multiple linked tables (e.g., Customers and Orders) stored in Excel
- Excel 365 (or Excel 2016+ with Data Model support)
- A table with a common field (e.g., CustomerID in both tables)
- Power Query (built into Excel) to refresh relationships
Step-by-Step
- Open the Data Model: Go to the Data tab and click Get & Transform Data in the Connections group. Then click Data Model (under the Power Query tab). This opens the Data Model view where you’ll see your tables as boxes. If labels differ: Some older Excel versions may show "Data Model" instead of "Power Query."
- Select the first table: Drag your primary table (e.g., Customers) into the Data Model workspace. Right-click the box and choose Show Table Relationships to see its fields. Key requirement: The primary table must have a field that links to the foreign key in the second table.
- Add the second table: Drag the linked table (e.g., Orders) into the workspace. The Data Model will prompt you to establish a relationship. Click OK. Field alignment: Ensure the cursor hovers over the correct field (e.g., CustomerID in Orders) before clicking the link icon.
-
Define the relationship:
A small line will appear connecting the tables. Right-click the line and choose Edit Relationship.
- Select the foreign key field in the Orders table (e.g., CustomerID)
- Click OK to confirm
- Repeat for any additional tables (e.g., Products)
- Test the relationship: Open a query in Excel. Go to Data > Query > New Query > From Tables and Relationships. Click OK to see the linked data appear. Trouble? If fields don’t match, right-click the relationship line > Edit Relationship and adjust fields again.
Common Mistakes
- Skipping validation: Without a primary key (e.g., CustomerID in Customers), Excel won’t enforce referential integrity. Add a unique identifier if missing.
- Wrong field types: Ensure both fields are text (strings) or number (integers). A date field won’t work in a numeric relationship.
- Overlapping values: If two tables have the same field name (e.g., ID), Excel will treat them as the same column, breaking the relationship.
- Ignoring Data Model updates: Refresh the Data Model (Data > Get & Transform Data > Refresh All) after adding new tables or changing data.
Tips
- Use Power Query for complex links: Export tables to Power Query, right-click a table > Add Table Relationship > From Current Table. Repeat for each linked column.
- Optimize performance: Select the relationship line, right-click > Show Table Relationships > uncheck Show All if you don’t need all tables in queries.
- Backup your Data Model: Save a copy of the Data Model as a separate file (.qwd) if you edit frequently.
- Replace incorrect relationships: Delete the old relationship between tables, then re-establish with valid fields.
Troubleshooting
- Relationships won’t display: Ensure both tables are linked to the same workbook. Right-click the missing link > Edit Relationship > check Show Table Relationships.
-
Data doesn’t update:
- Check if the primary key is unique (no duplicates).
- Refresh the Data Model (Refresh All).
- Manually run a query to validate the link.
- App crashes during editing: Close Power Query, restart Excel, and repeat the steps.
- Foreign key errors: Right-click the offending field > Remove from the relationship, then re-add it with correct field names.
Frequently Asked Questions
What if my tables are in different workbooks?
Link the workbooks first via Data > Get Data > From File > From Workbooks. Then add the relationship in the Data Model.
How do I delete an existing relationship?
Right-click the relationship line > Delete. Confirm by clicking Delete Relationships in the dialog.
Will Excel automatically handle updates?
Yes, if relationships are set up correctly. A refresh (Refresh All) ensures changes propagate to queries.
Can I use Excel Data Model with PivotTables?
Yes, but only if the PivotTable references the Data Model’s query. Right-click the PivotTable > Data > From Table/Query > Data Model.
What if my data has duplicates?
Use Data > Remove Duplicates to clean the primary table. Referential integrity won’t work with duplicates.
How do I convert an existing manual join to a Data Model relationship?
1. Combine the tables into a single Data Model table using Power Query. 2. Edit the relationship in the Data Model workspace.