Relational Tables in Excel: How to Link Data and Tables
In this article
To make relational tables in Excel, you must convert your data ranges into official Excel Tables, identify a unique identifier (Primary Key) for each table, and then link them using the Data Model via the Relationships tool. This process allows you to connect multiple tables—such as a "Customers" table and an "Orders" table—so you can analyze combined data in a single PivotTable without using complex VLOOKUP or XLOOKUP formulas.
What You'll Need
- Microsoft Excel (Office 365, 2019, or 2021 versions are recommended for full Data Model support).
- Two or more sets of data that share at least one common column (e.g., a Customer ID that appears in both a client list and a sales log).
- Data that is organized in rows and columns with clear headers.
Step-by-Step
- Prepare Your Data Ranges: Ensure your data is clean. Each column must have a unique header name, and there should be no completely empty rows or columns within the dataset. For a relational setup, ensure that one table (the "Lookup" or "Dimension" table) contains a list of unique values for the connecting key. For example, in a "Products" table, each Product ID should appear only once.
- Convert Ranges to Official Tables: Excel cannot create relationships between simple cell ranges; they must be formatted as Tables. Click anywhere inside your first data range and press
Ctrl + T(Windows) orCmd + T(Mac). Ensure the "My table has headers" box is checked and click OK. Repeat this for every dataset you intend to link. - Name Your Tables: To avoid confusion in the Data Model, give your tables descriptive names. Click inside a table, go to the Table Design tab on the ribbon, and enter a name in the Table Name box on the far left (e.g., change "Table1" to "tbl_Customers").
- Add Tables to the Data Model: You must tell Excel which tables should be part of the relational model. While a table is selected, go to the Power Pivot tab and click Add to Data Model. If you do not see the Power Pivot tab, you can also achieve this by creating a PivotTable and checking the box "Add this data to the Data Model" in the Create PivotTable dialog box.
- Create the Relationship: Navigate to the Data tab on the ribbon and click the Relationships button. In the dialog box that appears, click New....
- Define the Link: In the "Create Relationship" window, configure the following:
- Table: Select your "Fact" table (the one with many entries, like "tbl_Sales").
- Column (Foreign): Select the column that links to the other table (e.g., "CustomerID").
- Related Table: Select your "Dimension" table (the one with unique entries, like "tbl_Customers").
- Related Column (Primary): Select the matching unique column (e.g., "CustomerID").
- Build a Relational PivotTable: Now that the tables are linked, go to Insert > PivotTable. Select "Use this workbook's Data Model" as the source. In the PivotTable Fields pane on the right, you will now see all your linked tables. You can drag the "Customer Name" from the Customers table and the "Total Sales" from the Sales table into the same report, and Excel will automatically calculate the relationship.
Common Mistakes
One of the most frequent errors is attempting to create a relationship between two tables where neither table has a unique list of IDs. This is known as a "Many-to-Many" relationship. Excel's standard Relationship tool requires at least one of the tables to have a "One-to-Many" relationship, meaning the Primary Key in the lookup table must contain no duplicates. If you have duplicate IDs in both tables, Excel will return an error stating that the relationship cannot be created.
Another common mistake is forgetting to format the data as a Table (Ctrl+T) before attempting to use the Data Model. Users often try to link raw cells, but the Data Model only recognizes named Table objects. Additionally, users often fail to name their tables, leaving them as "Table1," "Table2," and so "Table3," which makes managing complex models nearly impossible once you have more than three tables.
Finally, mismatched data types are a major hurdle. If the "CustomerID" in your Sales table is formatted as Text, but the "CustomerID" in your Customers table is formatted as a Number, Excel will not recognize them as the same data, and the relationship will fail or return blank values in your PivotTable.
Tips
To keep your workbook performant, only add the columns to the Data Model that you actually need for reporting. If your source table has 50 columns but you only need three for your analysis, consider using Power Query (Data > Get Data) to remove unnecessary columns before loading the data into the model. This reduces the file size and speeds up PivotTable refresh rates.
Use a consistent naming convention for your keys. If you call the linking column "ClientID" in one table and "Customer_ID" in another, it is easy to get confused. Renaming them to be identical across all tables makes the relationship mapping process much faster.
Whenever you add new data to your source tables, remember that the PivotTable does not update automatically. You must go to the Data tab and click Refresh All to pull the new records through the relationship and into your report.
Troubleshooting
If you receive an error saying "The relationship cannot be created because the column contains duplicate values," you must find and remove the duplicates in your Dimension (lookup) table. To do this, select the ID column in that table, go to the Data tab, and click Remove Duplicates. Ensure that only one unique instance of each ID remains.
If your PivotTable shows "Blank" for values from the related table, check for trailing spaces in your ID columns. A cell containing "C101 " (with a space) is not the same as "C101". You can fix this by using the =TRIM() function in a helper column to remove extra spaces, then copying and pasting the values back over the original IDs.
If the Relationships button is greyed out, ensure that you have actually added your tables to the Data Model. The button only becomes active once there are at least two tables loaded into the internal Power Pivot engine. If you are using a very old version of Excel (pre-2013), this feature may not be available, and you will need to rely on VLOOKUP or upgrade your software.
Frequently Asked Questions
Can I link more than two tables together?
Yes, you can link as many tables as necessary. You can create a "star schema" where one central Fact table (like Sales) is linked to multiple Dimension tables (like Products, Customers, and Calendar).
Is this better than using VLOOKUP or XLOOKUP?
Yes, for large datasets. VLOOKUP requires you to physically pull data into a new column, which increases file size and slows down calculations. Relational tables keep the data separate and only link them during the analysis phase, which is much more efficient.
Do I need the Power Pivot add-in enabled?
While the basic "Relationships" tool is built into the Data tab of modern Excel, enabling the Power Pivot add-in gives you a visual "Diagram View" where you can see the tables and the lines connecting them, making it much easier to manage complex models.
What happens if I delete a row in one of the tables?
The relationship remains intact, but the PivotTable will no longer find the corresponding data for that deleted ID. It will typically show as a "(blank)" entry in your report until you refresh the data.
Can I create a relationship between two tables in different workbooks?
Not directly through the Relationships dialog. To link data from different files, you should use Power Query (Data > Get Data > From File) to import both tables into a single workbook's Data Model first.