Excel isn’t a database, but that hasn’t stopped people from using it as one. People have been doing this since early versions of Excel and creating relationships between different tables using VLOOKUP or INDEX and MATCH.

The good news is that more and more database like functionality is being added with each version, and since Excel 2013 we’ve been able to add relationships to tables.

Orders-and-Customer-Table How To Create Table RelationshipsIn our example we have an Orders table that contains data related to customer orders such as the Customer ID, Product Sold, and the Total. In another table called Customers we have the Name and Country for each Customer ID. But what do we do if we want to analyze our Orders data by customer Name or Country?

One solution would be to add two more columns to our Orders data and use a VLOOKUP function to bring in the customer Name and Country based on the Customer ID.

Another more elegant solution would be to use the pivot table Data Model to create a Relationship between the Orders table and the Customers table using the Customer ID field in both tables.

How-To-Create-Table-Relationships-Insert-Pivot-Table How To Create Table Relationships

Create a table based on the Orders table. Go to the Insert tab in the ribbon and select Pivot Table from the Tables section.

How-To-Create-Table-Relationships-Create-Pivot-Table-with-Data-Model How To Create Table Relationships

From the Create PivotTable menu.

  1. Select your Orders Table.
  2. Check the Add this data to the Data Model box.
  3. Press the Ok button.

Repeat these steps for the Customers table.

How-To-Create-Table-Relationships-PivotTable-Fields-with-all-Tables How To Create Table Relationships

With either of your pivot tables created, you should see both tables in the PivotTable Fields window from the All view. You can delete one of the pivot tables created since we only need one, the data will remain in the Data Model.

How-To-Create-Table-Relationships-Build-your-Pivot-Table-with-Name-and-Total How To Create Table Relationships

Build your pivot table with the Name from the Customers table in the Rows area and Total from the Orders table in the Values area.

  1. Drag the Name field from the Customers table to the Rows area. Expand the table to see fields by clicking the arrow next to the table name.
  2. Drag the Total field from the Orders table to the Values area.
  3. A notice will appear above the field list saying Relationships between tables may be needed. From here you can select Auto-Detect and let Excel guess the relationships between your tables or you can Create them yourself.

How-To-Create-Table-Relationships-Detecting-and-Creating-Relationships How To Create Table Relationships

If you choose Auto-Detect, Excel will work to create the relationships and you can check the results by pressing the Manage Relationships button or just Close the window. With this simple relationship, Excel is easily able to create the relationship. Small tables and consistent field names between tables will help Auto-Detect to work.

How-To-Create-Table-Relationships-Create-Relationship How To Create Table Relationships

If you choose to Create the relationships yourself then the Create Relationship menu will open.

  1. Select the Orders table as the main Table.
  2. Select Customer ID as the Column (Foreign).
  3. Select the Customers table as the Related Table.
  4. Select Customer ID as the Related Column (Primary).
  5. Press the OK button to finish creating the relationship.

How-To-Create-Table-Relationships-Resulting-Pivot-Table How To Create Table Relationships

Now your resulting pivot table contains the customer Name from the Customers table along with the correct corresponding Total from the Orders table.

How-To-Create-Table-Relationships-Create-Relationship-from-the-Ribbon-Analyze-or-Data-Tab How To Create Table Relationships

You can also create these relationships before trying to build the pivot table. You can do this from either the Data tab or the Analyze tab in the ribbon.

  • Find the Relationships button in the Data tab under the Data Tools section.
  • Find the Relationships button in the Analyze tab under the Calculations section.

How-To-Create-Table-Relationships-Manage-Relationships How To Create Table Relationships

This will open the Manage Relationships dialog box.

  1. Here you can see the existing relationships and select them to Edit, Activate, Deactivate or Delete.
  2. Create any new relationships using the New button.

This is an awesome way to avoid VLOOKUP or INDEX and MATCH, and minimize the columns in your tables.