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! Learn more

Reply
jcawley
Helper III
Helper III

Lowball M Code Question

Hello everyone,

So, I have a list of customer IDs with associated purchase dates:

Purchase DateCustomer IDCurrent Equipment
1/1/2022555Current
1/1/2022555Current
1/1/1999555Imported


What I am aiming to do is have a de-duplicated table that has unique Customer IDs, with the most recent Purchase Date and Current Equipment status. 

In the above example, it should read "Current".

Initially I attempted to sort from newest to oldest and then de-duplicate thinking it would keep the words "Current", but it did not. 

I'm assuming now what I need is some sort of M code fix the situation.

Any help would be greatly appreciated!

1 ACCEPTED SOLUTION
AdamVero
New Member

If you add a Table.Buffer( ) around your sort step that might be enough to do the job. Make sure your remove duplicates only looks at the relevant columns (might be just customer number) and it will keep the first row and remove others, so depending on the sort order it would keep the latest record.

When you do a Sort, there is some internal optimisation that basically means it does not completely sort every row. Table.Buffer forces it to complete the sort properly in order to then hold it in memory in a buffer.

View solution in original post

3 REPLIES 3
AdamVero
New Member

If you add a Table.Buffer( ) around your sort step that might be enough to do the job. Make sure your remove duplicates only looks at the relevant columns (might be just customer number) and it will keep the first row and remove others, so depending on the sort order it would keep the latest record.

When you do a Sort, there is some internal optimisation that basically means it does not completely sort every row. Table.Buffer forces it to complete the sort properly in order to then hold it in memory in a buffer.

Thank you! This worked!

bcdobbs
Community Champion
Community Champion

Hi, 

You want to use a group by on the id and then extract the latest record.

 

This should give you a good guide:

 

https://radacad.com/grouping-in-power-query-getting-the-last-item-in-each-group



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

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