Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel Table Relationships: How to Connect Data Tables

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Creating relationships in Excel allows you to connect two or more tables based on a common column, enabling you to analyze data from multiple sources in a single PivotTable without using complex formulas like VLOOKUP or XLOOKUP. This is achieved through the Data Model, which treats your spreadsheets like a relational database, linking a "lookup" table (containing unique IDs) to a "data" table (containing multiple entries for those IDs).

What You'll Need

  • Microsoft Excel (Office 365 or Excel 2013 and newer).
  • Two or more sets of data formatted as official Excel Tables (Insert > Table).
  • A common column (Primary Key) that exists in both tables, such as a Customer ID, Product SKU, or Order Number.
  • One of the tables must contain a list of unique values for the connecting column (no duplicates allowed in the lookup table).

Step-by-Step

  1. Format Your Data as Tables: Select your first range of data and press Ctrl + T (or go to Insert > Table). Ensure "My table has headers" is checked. Repeat this for every dataset you intend to link. Give each table a descriptive name by selecting the table, going to the Table Design tab, and typing a name in the Table Name box (e.g., "SalesData" and "ProductList").
  2. Verify the Common Column: Ensure both tables have a column with the exact same type of data. For example, if you are linking a Sales table to a Product table, both must have a "ProductID" column. The Product table must have unique ProductIDs (one row per product), while the Sales table can have the same ProductID appearing many times.
  3. Open the Relationships Dialog: Go to the Data tab on the top ribbon. In the Data Tools group, click the Relationships button. Note that menu labels may differ slightly depending on your version of Excel or region.
  4. Create the New Relationship: In the Relationships window, click the New button. A dialog box will appear asking you to define the link.
  5. Define the Table and Column Pair:
    • Table: Select the table that contains multiple instances of the ID (the "Many" side, e.g., SalesData).
    • Column (Foreign): Select the common column in that table (e.g., ProductID).
    • Related Table: Select the table that contains the unique list of IDs (the "One" side, e.g., ProductList).
    • Related Column (Primary): Select the matching column in that table (e.g., ProductID).
  6. Save and Close: Click OK to establish the relationship, then click Close to exit the Relationships manager.
  7. Build a PivotTable Using the Relationship: Go to Insert > PivotTable. In the dialog box, check the box that says "Add this data to the Data Model." This is a critical step; if you do not add the data to the Data Model, Excel will not recognize the relationships you just created.
  8. Analyze the Linked Data: In the PivotTable Fields pane, you will now see all your connected tables. You can drag the "Product Category" from the ProductList table and the "Total Sales" from the SalesData table into the same PivotTable, and Excel will automatically calculate the totals correctly based on the relationship.

Common Mistakes

One of the most frequent errors is attempting to create a relationship between two tables that both contain duplicate values in the connecting column. Excel requires a "One-to-Many" relationship. If both tables have duplicate IDs, Excel will return an error stating that the relationship cannot be created because the column contains duplicate values. You must ensure the "Related Table" (the lookup table) has a unique list of identifiers.

Another common mistake is forgetting to check the "Add this data to the Data Model" box when creating the PivotTable. Users often set up the relationship correctly in the Data tab but then create a standard PivotTable. In a standard PivotTable, the tables remain isolated, and attempting to pull fields from different tables will result in a "#VALUE!" error or blank cells because the PivotTable isn't utilizing the Data Model engine.

Data type mismatches are also prevalent. If one table stores the Product ID as a Number and the other stores it as Text (even if they look identical), Excel will not recognize them as the same value. This often happens when importing data from CSV files where IDs might be formatted as text by default.

Tips

To keep your workbook organized, always rename your tables immediately after creating them. Using names like "Table1" and "Table2" makes the Relationships dialog confusing, especially when you are dealing with five or more connected tables. Use clear names like "tbl_Customers" or "tbl_Orders".

If you have a very large dataset, using relationships is significantly more efficient than using VLOOKUP or XLOOKUP. Formulas calculate every time a cell changes, which can slow down your workbook. Relationships are handled by the Power Pivot engine, which compresses data and processes links much faster, reducing file size and increasing calculation speed.

Consider using the "Diagram View" if you have many tables. While the standard Relationships window is a list, you can access the Diagram View by going to the Power Pivot tab (if enabled) and clicking Manage. This allows you to see a visual map of your tables and the lines connecting them, making it easier to spot missing links or logic errors in your data architecture.

Troubleshooting

If you receive an error saying "The relationship cannot be created because the column contains duplicate values," you must clean your lookup table. To find duplicates, select the ID column in your lookup table, go to Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values. Once highlighted, remove the duplicates by going to the Data tab and clicking "Remove Duplicates".

If your PivotTable shows "(blank)" for values from the related table, check for trailing spaces in your ID columns. A cell containing "ID123 " (with a space) will not match "ID123". Use the TRIM function in a helper column to remove extra spaces, then copy and paste the cleaned values back into the table as values.

If the Relationships button is greyed out, ensure that your data is actually formatted as Tables (Ctrl + T) and not just as ranges of cells. The Data Model requires official Excel Table objects to function.

If you cannot find the Power Pivot tab to use the Diagram View, you may need to enable it. Go to File > Options > Add-ins. In the "Manage" dropdown at the bottom, select "COM Add-ins" and click Go. Check the box for "Microsoft Power Pivot for Excel" and click OK.

Frequently Asked Questions

Can I create a many-to-many relationship in Excel?

Excel does not natively support direct many-to-many relationships in the standard Relationships dialog. To achieve this, you must create a "bridge table" (or junction table) that contains unique pairs of the IDs from both tables, effectively turning one many-to-many relationship into two one-to-many relationships.

Do I still need VLOOKUP if I have relationships?

For reporting in PivotTables, no. Relationships replace the need to pull data from one table into another using VLOOKUP. However, if you need a specific value to appear in a cell on a standard worksheet for a calculation, VLOOKUP or XLOOKUP is still the correct tool.

Will relationships work in older versions of Excel?

Relationships and the Data Model were introduced in Excel 2013. If you send a file with relationships to someone using Excel 2010 or older, the relationships will not function, and the PivotTable will likely break or show errors.

How many tables can I link together?

There is no strict small limit on the number of tables you can link; you can connect dozens of tables. However, the complexity of your data model can impact performance. The more tables you link, the more important it is to maintain clean, unique primary keys.

Does changing data in a table automatically update the relationship?

Yes, the relationship itself remains intact. However, the PivotTable does not refresh automatically. After updating the data in your tables, you must go to the PivotTable, right-click, and select "Refresh" to see the updated results based on the established relationships.