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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
GuilleATT
Frequent Visitor

Merge query is acting weird

Hi,

 

I have a Sales table with closed dates between other variables and I'm trying to create a new column in Power Query to indicate if the Sales is the first time that happens for an AccountID. 

This way, I duplicated my Sales table, reduce it only to be AccountID and ClosedDate, ordering it ascending and removing duplicates on AcccountID column to obtain the first time a Sales happen to each AccountID.

 

Then on the original sales table, which is filtered now only for 2020, I merge it with the duplicated one to do what an Excel is a simple VLoopUk...

 

What my surprise is when expanding the columns of the merged table the dates retrieved aren't correct and even some dates retrieved are no longer part of the duplicated table since I removed duplicates...

 

Appreciate any help on this since it's driving me crazy.

 

Best,

 

Guillermo

1 ACCEPTED SOLUTION

Hi @GuilleATT ,

the behaviour you're seeing would happen if you don't use a Table.Buffer when sorting before removing duplicates: https://community.powerbi.com/t5/Community-Blog/Bug-warning-for-Table-Sort-and-removing-duplicates-i...

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

@GuilleATT - Can you post sample data or a link to your PBIX? Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @GuilleATT ,

the behaviour you're seeing would happen if you don't use a Table.Buffer when sorting before removing duplicates: https://community.powerbi.com/t5/Community-Blog/Bug-warning-for-Table-Sort-and-removing-duplicates-i...

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Awesome, that worked, thank you so much!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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 Solution Authors