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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
o59393
Post Prodigy
Post Prodigy

Merged queries is duplicating values

Hi all

 

I need to add a column from one table to another using merge queries in Power query, in order to go from this is in table called "lines" 

dsfdsfs.JPG

 

to this:

rdeires.JPG

 

As seen, each of the 3 products or row, were assigned all the available months. So, column F "month" highlighted in light blue is the result desired.

 

When I merge the queries by common field country:

merge1.JPG

 

I am getting months duplicated or more by each of the 3 products, which is incorrect:

merge2.JPG

 

How can I get it right?

 

The result desired is in the excel attached.

 

https://1drv.ms/u/s!ApgeWwGTKtFdhn1PztJLnkIbOkgM?e=ucmaxr

 

Thanks!

 

1 ACCEPTED SOLUTION
AllisonKennedy
Super User
Super User

You have 'Cardboard' and 'Plastic' in your Month and Units table, so you get a month for each of those Materials, therefore you're getting 19 months * 3 rows in Lines table * 2 Materials in Month and Units table = 114 rows total.

I don't really understand why you need to duplicate the rows in the Lines table for each month? Can you use a DimDate table and some measures to achieve this result instead?

Otherwise try referencing the Month & Units table in a new query, do a Remove Duplicates on the Month column and use that for your merge.

Advanced Editor M script for the referenced query:

let
Source = Table2,
#"Removed Duplicates" = Table.Distinct(Source, {"Month"})
in
#"Removed Duplicates"

Where Table2 is your Month & units table.

Then use that new Query (name it DistinctMonths ? or something that makes sense to you) as your second table in the merge.

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

4 REPLIES 4
Syndicate_Admin
Administrator
Administrator

@o59393 Good afternoon, I ask you a question. I have the same problem where "for a certain critero (reason for high / low of employees of the month) brings me the values that coincide with such a person of my payroll of employees"; thus doubling the values for certain employees. In your case how did you solve it? I'm not sure what answers you were given.

Thanks in advance

danextian
Super User
Super User

Hi @o59393 

@AllisonKennedy  is right. Unlike the vlookup in Excel which will return the first matching row, the Merge Query in Power BI behaves similar to SQL - you'll get all rows for every match.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi @AllisonKennedy  and @AllisonKennedy 

 

It was an error on my end that was duplicating the months. 

 

Thanks for the help! 

AllisonKennedy
Super User
Super User

You have 'Cardboard' and 'Plastic' in your Month and Units table, so you get a month for each of those Materials, therefore you're getting 19 months * 3 rows in Lines table * 2 Materials in Month and Units table = 114 rows total.

I don't really understand why you need to duplicate the rows in the Lines table for each month? Can you use a DimDate table and some measures to achieve this result instead?

Otherwise try referencing the Month & Units table in a new query, do a Remove Duplicates on the Month column and use that for your merge.

Advanced Editor M script for the referenced query:

let
Source = Table2,
#"Removed Duplicates" = Table.Distinct(Source, {"Month"})
in
#"Removed Duplicates"

Where Table2 is your Month & units table.

Then use that new Query (name it DistinctMonths ? or something that makes sense to you) as your second table in the merge.

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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