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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors