Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Jakez
New Member

How to join two tables which are non unique

Hi All,

 

I have two tables as shown below and i want to merge them together to do some analysis in Powerbi, original source of the data is excel files. I want to join the table using two columns Dealer_id and Date.  

Table 1

Dealer_idDateL_idCountAlt_c
234401/01/2023232345333
234402/01/2023324234224
234403/01/20232242453456
234404/01/2023444242243

 

Table 2

Dealer_idDate Sales
234401/01/2023 4500
234402/01/2023 3499
234403/01/2023 2133
234404/01/2023 2344

 

Desired Output

Dealer_idDateL_idCountAlt_cSales
234401/01/20232323453334500
234402/01/20233242342243499
234403/01/202322424534562133
234404/01/20234442422432344

 

What i  really need from  is to get the Sales from table 2 into table 1,  i get the desired output in powerquery but when i apply and close Power query and when the data loads i get the following error "Column Dealer_id in table1 contains a duplicate value '2344' and this is not allowed for columns on the one side of a many to one relationship or for columns that are useed as primary key of a table"

 

PLease advise how i can solve this.

Thanks

1 ACCEPTED SOLUTION
AntrikshSharma
Super User
Super User

@Jakez 

  1. Disable "Auto Detect Relationship" under file settings.
  2. Before loading data make sure there are no existing relationships.
  3. You can join 2 table by using DealerID and Date as the Key
let
    Source = 
        Table.NestedJoin (
            Table1,
            { "Dealer_id", "Date" },
            Table2,
            { "Dealer_id", "Date" },
            "Table2",
            JoinKind.LeftOuter
        ),
    ExtractedSales = Table.ExpandTableColumn ( Source, "Table2", { " Sales" }, { " Sales" } )
in
    ExtractedSales

 

View solution in original post

3 REPLIES 3
AntrikshSharma
Super User
Super User

@Jakez 

  1. Disable "Auto Detect Relationship" under file settings.
  2. Before loading data make sure there are no existing relationships.
  3. You can join 2 table by using DealerID and Date as the Key
let
    Source = 
        Table.NestedJoin (
            Table1,
            { "Dealer_id", "Date" },
            Table2,
            { "Dealer_id", "Date" },
            "Table2",
            JoinKind.LeftOuter
        ),
    ExtractedSales = Table.ExpandTableColumn ( Source, "Table2", { " Sales" }, { " Sales" } )
in
    ExtractedSales

 

Works fine, Thanks Antriksh!

For the uninititated, you have to create a new Query to paste the above code in Advanced editor.

Also, remove the space before {" Sales"} to avoid error.

ronrsnfld
Super User
Super User

I cannot reproduce your problem with the information you have provided. How, exactly, did you merge the tables in Power Query?

 

I merely selected to get data from Excel; selected the file and then the two tables.

In PQ, I selected to merge the two tables to a new query, using a full outer join, and then extracting the Sales column.

 

If you did something different, please tell us what you did, and supply the M-Code from the Advanced Editor.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors