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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Most recent record from another table

Hi - I have two tabels with a many to relationship by ID. In Table 1 I have Note entries and there are multiple per ID. In table 2 I want to bring in the most recent date for each ID as well as the most recent note. In my sample date you can see that I only pull in the most recent date and note into table 2. How do I code these two fields in DAX?

 

Table 1:

IDDateNote
1235/10/2020Note 1
1235/15/2020Note 2
1236/5/2020Note 3
1236/15/2020Note 4
4566/18/2020Note 1
4566/24/2020Note 2

 

Table 2:

IDDateNote
1236/15/2020Note 4
4566/24/2020Note 2
2 ACCEPTED SOLUTIONS
az38
Community Champion
Community Champion

Hi @Anonymous 

try  a table

Table 2 = SUMMARIZECOLUMNS('Table 1'[ID], 
"Date", MAX('Table 1'[Date]),
"Note", CALCULATE(MAX('Table 1'[Note]), FILTER('Table 1', 'Table 1'[Date]=[Date] && 'Table 1'[ID]=[ID])
))

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

mahoneypat
Microsoft Employee
Microsoft Employee

Here are two expressions for your calculated columns

 

Latest Date = CALCULATE(MAX(Table1[Date]))

 

Latest Note = CALCULATE(MAX(Table1[Note]), Table1[Date] = Table2[Latest Date])

 

The 2nd one uses the result of the first one.

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous , I have done it using lastnonblankvalue , released in March 2020.

Check: https://www.dropbox.com/s/hkzx1lrnif38y1v/Last%20non%20blank%20loop.pbix?dl=0

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
mahoneypat
Microsoft Employee
Microsoft Employee

Here are two expressions for your calculated columns

 

Latest Date = CALCULATE(MAX(Table1[Date]))

 

Latest Note = CALCULATE(MAX(Table1[Note]), Table1[Date] = Table2[Latest Date])

 

The 2nd one uses the result of the first one.

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


az38
Community Champion
Community Champion

Hi @Anonymous 

try  a table

Table 2 = SUMMARIZECOLUMNS('Table 1'[ID], 
"Date", MAX('Table 1'[Date]),
"Note", CALCULATE(MAX('Table 1'[Note]), FILTER('Table 1', 'Table 1'[Date]=[Date] && 'Table 1'[ID]=[ID])
))

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

Thanks, but I'd rather not have to have another table just for this. Table 2 already exists and has more columns in it than just my sample data. I just want to pull in the most recent note from Table 1.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.