How to Create Relationship in Excel with Duplicate Values

The sample dataset has Duplicate values. The common column is the Product Id. The Relationship will be based on this common column.

How to Create Relationship in Excel with Duplicate Values


Method 1 – Appending Common Table

As we have Duplicate values in both tables, we can’t create a Relationship among them in Excel. Since this Relationship will require a one-to-one Relationship and Excel does not support it, we will import the tables on the power query and append them together and remove the Duplicates from the appended table. We will create Relationships with this new table with the original two tables.

Steps:

  • We have two separate tables between which we need to create a Relationship, based on the common column Product Id.
  • In order to create Relationships among tables, we need to have at least unique values in one of the tables.
  • We have Duplicate values in both of the table’s Product Id columns.

Appending Common Table to Create Relationship in Excel with Duplicate Values

  • To demonstrate why we can’t create a Relationship among the table, follow the steps, where we will try to make a relationship between these two tables.
  • Select the range of cells B4:C16 and click on the Table command from the Insert tab.

creating table from ranged dataset to create relationship with duplicate values in Excel

  • In the Create Table dialog box, re-confirm the table range.
  • Check the My table has headers checkbox.

  • To demonstrate why we can’t create a Relationship among the table, follow the steps below, where we will try to make a relationship between these two tables.
  • Select the range of cells B4:C16 and click on the Table command from the Insert tab.

make table from dataset

  • In the Create Table dialog box, re-confirm the table range.
  • Check the My table has headers checkbox.

  • Create a pivot table from the two created tables.
  • Select the first table and go to Insert tab > PivotTable > From Table/Range.

add table to the pivot table

  • Click on the New Worksheet.
  • Check the Add this data to the Data Model checkbox.
  • Click OK.

  • Select the second table and go to Insert tab > PivotTable > From Table/Range.

add table to the pivot table

  • Click on New Worksheet.
  • Check Add this data to the Data Model.
  • Click OK.

Appending Common Table to Create Relationship in Excel with Duplicate Values

  • In the new worksheet, there is a PivotTable Fields menu.
  • The side panel is occupied by both tables. To observe both tables, click on All section.

  • Drag the Product Id field below the Filter area.
  • Drag Revenue and Profit from Table2 and Cost and Quantity from Table3.
  • The Revenue and Profit shows the values, but the Quantity and Cost column is showing the same values for each row.
  • To resolve this issue, create a Relationship among the two tables..

  • Place cursor at any point in the table. Enable the Power Pivot feature in Excel and click on the Power Pivot tab.
  • Click on the Add to Data Model.

open data model to add table to create relationship among tables

  • In the data model, both tables are loaded.

  • Switch to the Diagram view by clicking on the Diagram view in the Home tab.

  • From the Design tab, click on Create Relationship.

creating relationships among tables

  • In the Create Relationship dialog box, select Table2 and Table3 in the dropdown box.
  • A warning sign will be displayed.
  • Click Cancel.

  • Open a power query and append two separate tables.
  • Using that appended table we are going to create Relationships that will help us to obtain the desired results.
  • Select the Table2.
  • From the Data tab, go to Get Data > From Other Sources > Form Table/Range.

add data to data model to create relationship

  • Table2 is now loaded in the new window.

  • Follow the same steps for Table3.

  • Right-click on Table2, and click on the Add as New Query.

 Appending Common Table to Create Relationship in Excel with Duplicate Values

  • From the new query listed, right click on the List.
  • Click on To Table.

 Appending Common Table to Create Relationship in Excel with Duplicate Values

  • In the next window, click OK.

  • Right-click on Table2 and click on the Add as New Query.

Appending Common Table to Create Relationship in Excel with Duplicate Values

  • From the new query listed, right click on the List.
  • Click on To Table.

  • In the next window, click OK.

  • We now have two separate columns that are excluded from their table, in different queries.

  • Append the Product Id and Product Id (2).
  • Select table Product Id and click on the Append Queries from the Combine group.
  • From the drop-down menu, click on the Append Queries.

  • A window will appear.
  • Click on the Product Id (2), from the Table to append option.
  • Click OK.

  • Product Id (2) table now appends with the Product Id table.
  • In the newly appended table, right-click on the table and select Remove Duplicates.

  • All of the Duplicates are removed.
  • Close the power query table. Click on Keep.

  • The newly created tables will load in separate sheets.
  • Go to the worksheet named Product Id.
  • Click on the Add to Data Model, from the Power Pivot tab.

  • The new table is now available at the Power pivot.
  • In the Design tab, click on Create Relationship.

  • In the Create Relationship window, select Table2 and Product Id.
  • Click OK.

  • In the diagram view, we can see that there is a Relationship created between Table2 and Product Id.

● In the following window, do nothing and click OK.

  • In the Create Relationship window, select Table3 and Product Id.
  • Click OK.

  • In the diagram view, we can see that there is a Relationship created between Table3 and Product Id.

relationship of new table create with the table 2 and table 3 whose have duplicate values

  • Go to the original pivot table report.
  • Remove all the existing fields and enter the fields shown below.
  • Add the Product Id field in the Rows.
  • Drag the Revenue to the values.
  • You can see some issues are present.
  • There is a yellow notice area, which indicates the presence of a Relationship among the tables.
  • Click on the Auto-Detect.

  • A dialog box will appear.
  • It will take some time to link the Relationship.
  • The Relationship will be found and linked.
  • Click Close.

 

  • Drag Revenue and profit from Table2_2.
  • Drag the quantity and cost from Table3_2.
  • If there is any Relationship, a yellow warning is shown, click Auto Detect.
  • The pivot table is showing the correct values, according to the Relationship we created earlier.

Relationship in between two table created with similar values

Read More: Create Entity Relationship Diagram from Excel


Method 2 – Deleting Duplicate Values

Steps:

  • We have two separate tables between which we need to create a Relationship, based on the common column Product Id.
  • In order to create Relationships among tables, we need to have unique values in one of the tables.
  • But here we have Duplicate values in both of the table’s Product Id columns.

Deleting Duplicate Values to Create Relationship in Excel with Duplicate Values

  • Select the range of cells B4:C16 and click on the Table command from the Insert tab.

insert table from ranged dataset in order to create relationship with duplicate values in Excel

  • In the Create Table dialog box, re-confirm the table range.
  • Check the My table has headers checkbox.

  • Select the range of cells B4:C16 and click on the Table command from the Insert tab.

make table from ranged dataset

  • In the Create Table dialog box, re-confirm the table range.
  • Check the My table has headers checkbox.

  • Open a power query and delete Duplicate values from the table.
  • Select the Table1.
  • From the Data tab, go to Get Data > From Other Sources > Form Table/Range.

add table to the data model to make Relationship in Excel with same Values

  • A new window opens.
  • Table1 is now loaded.

table with duplicate values are loaded in the data model to create relationship

  • Follow the same steps for Table2.

insert table to data model to create Relationship with duplicate Values in Excel

  • In Table1, right-click on the Product Id and select Remove Duplicates.

remove duplicate value to make relationship

  • All of the Duplicates are now removed.

  • Do the same for Table2.
  • In Table2, right-click on the table and select Remove Duplicates.

  • The table will look like the one below.

table after their duplicate values are removed for producing relationship

  • Click on the Close & Load To from the Home tab.

close and load to produce Relationship in Excel with similar Values

  • The table will load in different sheets.
  • Add them to the pivot table.
  • Select the loaded Table1 and go to Insert tab > PivotTable > From Table/Range.

add second table with has duplicate values to create relationship in excel

  • In the next dialog box, click on the Existing Worksheet and the location of the table.
  • Check the Add this data to the Data Model checkbox.
  • Click OK.

  • Select the loaded Table2 and go to Insert tab > PivotTable > From Table/Range.

add intermediate table with duplicate Values to data model with duplicate Values

  • In the next dialog box, click on the Existing Worksheet and the location of the table.
  • Tick the Add this data to the Data Model checkbox.
  • Click OK.

  • Drag the Product Id from Table1_2 to the Rows.
  • Drag Revenue and Profit from Table1_2 and Cost and Quantity from Table2_2 to the values.
  • The value of the cost and quantity columns in the pivot table are incorrect.

Relationship detected in pivot table field for duplicate values

  • To resolve this, click on CREATE on the Yellow Warning box.

  • In the Edit Relationship window, choose Table2_2 and Table 1_2 in the first and second dropdown menus.
  • Select Product Id in both the Column (Foreign) and Related Column (Primary) dropdown menu.
  • Click OK.

  • The Relationship will solve the issue and the Cost and Profit columns will show accurate values.

Relationship in between two table created with duplicate values in Excel

Read More: How to Create Data Model Relationships in Excel


Download Practice Workbook


Get FREE Advanced Excel Exercises with Solutions!
Rubayed Razib Suprov
Rubayed Razib Suprov

Rubayed Razib, holding a BSC degree in Naval Architecture & Engineering from Bangladesh University of Engineering and Technology, serves as a devoted member of the ExcelDemy project. He has contributed significantly by authoring numerous articles and showcasing proficiency in VBA. Razib efficiently automates Excel challenges using VBA macros and actively participates in the ExcelDemy forum, providing valuable solutions for user interface challenges. Apart from creating Excel tutorials, he is interested in Data Analysis with MS Excel,... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo