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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
nok
Advocate II
Advocate II

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?

1 ACCEPTED SOLUTION
v-dineshya
Community Support
Community Support

Hi @nok ,

Thank you for reaching out to the Microsoft Community Forum.

 

Please refer below Calculated column.

 

Status =
VAR latestDate =
    CALCULATE(
        MAX(History[EditDate]),
        FILTER(History, History[ID] = Orders[ID])
    )
RETURN
    CALCULATE(
        MAX(History[Status]),
        FILTER(
            History,
            History[ID] = Orders[ID] &&
            History[EditDate] = latestDate
        )
    )
 
Please refer output snap and attched PBIX file.
 
vdineshya_0-1759745865445.png

 

 

I hope this information helps. Please do let us know if you have any further queries.

 

Regards,

Dinesh

 

 

View solution in original post

7 REPLIES 7
v-dineshya
Community Support
Community Support

Hi @nok ,

Thank you for reaching out to the Microsoft Community Forum.

 

Please refer below Calculated column.

 

Status =
VAR latestDate =
    CALCULATE(
        MAX(History[EditDate]),
        FILTER(History, History[ID] = Orders[ID])
    )
RETURN
    CALCULATE(
        MAX(History[Status]),
        FILTER(
            History,
            History[ID] = Orders[ID] &&
            History[EditDate] = latestDate
        )
    )
 
Please refer output snap and attched PBIX file.
 
vdineshya_0-1759745865445.png

 

 

I hope this information helps. Please do let us know if you have any further queries.

 

Regards,

Dinesh

 

 

danextian
Super User
Super User

Hi @nok 

You can use TOPN (top 1) on history table filtered by order ID and sorted by Edit Date in descending order and then return the status

Latest Status = 
VAR _ID = Orders[ID]
VAR _History =
    TOPN ( 1, FILTER ( History, History[ID] = _ID ), History[EditDate], DESC )
RETURN
    MAXX ( _History, [Status] )

danextian_0-1759558962064.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
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 Commander
Kudo Commander

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!///

wardy912
Solution Sage
Solution Sage

Hi @nok 

 

Load both tables into Power Query.
In the History table:

Sort by EditDate descending.
Use "Remove Duplicates" on the ID column — this keeps the row with the most recent date.


Now, go to the Orders table:

Use "Merge Queries" to join with the filtered History table on ID.
Expand the Status column from the merged table.

 

This will give you the desired result.

 

--------------------------------

I hope this helps, please give kudos and mark as solved if it does!

 

Connect with me on LinkedIn.

Subscribe to my YouTube channel for Fabric/Power Platform related content!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

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
Top Kudoed Authors