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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
rjtedge
Frequent Visitor

Return most recent record from another table

Hi, 

 

I have two tables in power bi. Table 1 is a list of customers, Table 2 has a list of sales. I want to create a new column in Table 1 that contains the most recent sale item for each customer. Can't seem to make it work with DAX. 

 

Table 1

CUSTOMER IDCUSTOMER NAME
1James
2Joe
3John

Table 2

SALEITEMCUSTOMER IDSALE DATE
1Apple11/1/2022
2Peach21/2/2000
3Apple11/5/2001
4Banana38/2/2021
5Peach11/2/2000
6Banana21/8/2000

 

Cheers

Rob

1 REPLY 1
Ashish_Mathur
Super User
Super User

Hi,

Create a relationship (Many to One and Single) from Table2 to Table1.  Create a Calendar Table and a relationship (Many to One and Single) from the Sale Date of Table2 to the Date column of the Calendar Table.  To your Table visual, drag the fields from Table1.  Write these measures

Farthest date = max('Table2'[Sale date])

Last item bought = calculate(min('Table2'[Item]),datesbetween(Calendar[Date],[Farthest date],[Farthest date]))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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