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
Anonymous
Not applicable

Finding most recent values between two tables

I've tried a couple of M formulas from older posts but I'm in the weeds with this one as an M Language novice.

 

I have two tables. Both can be linked via the unique identifier "machine number". Periodically they need a part replaced, which is shown in the "Part Number" column, in the Part Numbers table when the new item has gone in:

LCreek_0-1667564965647.png


In the other table is a record of customer complaints, which shows when a complaint has been completed by Machine Number (Complaints Table):

LCreek_1-1667564991983.png


I need to find a way to link the two together that tells me, for a given Complaint Completed Date (Complaints Table) what Part Number (Part Numbers Table) the Machine Number had.

For example: the Complaint Completed on 02/01/2021 should return a value of Part Number "1", whereas the Complaint Completed on 22/01/2021 should return me a Part Number "2" and so on. Any guidance appreciated! 🙂 




1 ACCEPTED SOLUTION
jennratten
Super User
Super User

Hello - this will do the trick... You will need to add the name of your previous step into the first line where indicated.  Also, if your tables are named something other than "Parts Table" and "Complaints Table" then you will need to update those names in the script also.  Please let me know if you have any questions.

 

jennratten_1-1667569599397.png

 

Table.AddColumn(#"Your Previous Step Name Goes Here", "Custom", each List.Max ( Table.SelectRows(#"Parts Table", (x)=> x[Machine number]=[Machine number] and x[Release Date] < [Complaint Completed Date])[Part Number] ), Int64.Type)

  

View solution in original post

1 REPLY 1
jennratten
Super User
Super User

Hello - this will do the trick... You will need to add the name of your previous step into the first line where indicated.  Also, if your tables are named something other than "Parts Table" and "Complaints Table" then you will need to update those names in the script also.  Please let me know if you have any questions.

 

jennratten_1-1667569599397.png

 

Table.AddColumn(#"Your Previous Step Name Goes Here", "Custom", each List.Max ( Table.SelectRows(#"Parts Table", (x)=> x[Machine number]=[Machine number] and x[Release Date] < [Complaint Completed Date])[Part Number] ), Int64.Type)

  

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