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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
nok
Helper III
Helper III

Fetch value from another table where date is more recent

Hi!

I have two tables that follow this structure:

Orders

ID      Amount
AA12
AA88
BB34
CC90
CC56
DD23

 

History

IDStatusEditDate
AA    Ok23/09/2025    
AADelayed14/03/2025
BBIn progress   15/04/2025
BBOk21/01/2025
CCIn progress29/06/2025
CCFailed31/12/2025
CCOk01/12/2023
DDDelayed03/03/2024
DDContact11/12/2020

I want to create a column in the "Orders" table that retrieves the value of the "Status" column in the "History" table (through the ID relationship), but only the status where the EditDate column is the most recent date for that specifi ID. The end result would be something like this:

IDAmountStatus
AA    12Ok
AA88Ok
BB34In progress   
CC90In progress
CC56Failed
DD23Delayed


How can I do this?

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

=LOOKUPVALUE(History[Status],History[EditDate],CALCULATE(MAX(History[EditDate]),FILTER(History,History[ID]=EARLIER(Orders[ID]))),History[ID],Orders[ID])

Hope this helps.

Ashish_Mathur_0-1759552947810.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Nabha-Ahmed
Kudo Collector
Kudo Collector

Hi @nok 

You can do this easily using DAX by creating a calculated column in your Orders table that looks up the most recent status from the History table for each ID.

Here’s how:

 

Status =
VAR currentID = Orders[ID]
VAR LatestDate =
CALCULATE (
MAX ( History[EditDate] ),
FILTER ( History, History[ID] = currentID )
)
RETURN
CALCULATE (
SELECTEDVALUE ( History[Status] ),
FILTER (
History,
History[ID] = currentID &&
History[EditDate] = LatestDate
)
)

  
Thanks🌹

 

 

 

 

 

 

 

Shahid12523
Community Champion
Community Champion

LatestStatus =
VAR CurrentID = Orders[ID]
VAR LatestDate =
CALCULATE(
MAX(History[EditDate]),
History[ID] = CurrentID
)
RETURN
CALCULATE(
MAX(History[Status]),
History[ID] = CurrentID,
History[EditDate] = LatestDate
)

Shahed Shaikh
kpost
Super User
Super User

1) Open Power Query, pull up your History table. Make sure that "ID" is formatted as text and the "Date" column is formatted as date.

 

2) Duplicate the History Table.  Call it something descriptive like "History_Maxdate".  Immediately un-select "Enable Load", as you will not be integrating this table into your semantic model.

enable_load.PNG

 

3) Remove the "Status column" from your new History_Maxdate table.

 

4) Do a "Group by" on your History_Maxdate table and group by the ID, using MAX(Date) as the grouping.

step1_.PNG

 

5) You should now have a table with Unique IDs in the first column and the "latest" of the dates for each one in the second column.

table_so_Far.PNG

 

 

6) Now you want to do a "Merge" between this "History Maxdate" table and your "History" table, like so, selecting both the ID and the Date columns.  


merge_.PNG

 

7) Now you want to "Expand" that new column, selecting only the "status" field.

expand_.PNG

 

8 ) ou should now have all of the correct Status values for the latest date.

 

status_.PNG

 

9) Next you want to do another 'Merge', this time from your Order table to this History Maxdate table, only on the ID column.

merge2.PNG

 

 

 

10) Expand the new column by bringing in only the 'Status', and voila you are done.

only_Status.PNGdone___.PNG

'

 

See the attached .pbix file with your solution implemented.  And if this solution solves your problem for you, please mark 'Accept as Solution!'  Thank you.

 

(BTW, I think in your desired result table you had a typo?  It should say "Failed" for both CC orders instead of "In Progress" for one and "Failed" for the other. 

 

///Mediocre Power BI Advice, but it's free!///

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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