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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
DmitryKo
Helper IV
Helper IV

Last known status at given date

Disclaimer: I know there are several similar topics here, but neither of them has correct answer, so here goes another try.

 

Data is a typical sequential log file that represents status changes for a set of entities over time - similar to this:

DateTimeKeyStatus
2022-10-22 7:03ANew
2022-11-01 3:00BNew
2022-11-02 11:01AApproved
2022-11-02 17:00ACancelled
2022-11-03 8:00ARevised
2022-11-04 7:00BApproved

 

Notes (this is important since usually suggested solutions do not work as they use wrong assumptions):

  • There may be more than one status update (row) per given key in the log table
  • DateTime (timestamps of changes) appear at random intervals; it's not guarateed to have a row per each date from the calendar

 

What we want is to know key's current status as of any given date (EoD of this given date to be precise). For the example dataset above, this would be:

 

DateAB
2022-10-22New(null)
2022-10-23New(null)
.........
2022-11-01NewNew
2022-11-02CancelledNew
2022-11-03RevisedNew
2022-11-04RevisedApproved

 

Can this be achieved with DAX measure?

7 REPLIES 7
tamerj1
Super User
Super User

Hi @DmitryKo 

please try

=
MAXX (
CALCULATETABLE (
TOPN ( 'Table', 'Table'[DateTime], Asc ),
'Date'[Date] <= MAX ( 'Date'[Date] )
),
'Table'[Status]
)

This is even syntaxically incorrect

@DmitryKo 

Typo mistake 

=
MAXX (
CALCULATETABLE (
TOPN ( 1, 'Table', 'Table'[DateTime], Asc ),
'Date'[Date] <= MAX ( 'Date'[Date] )
),
'Table'[Status]
)

Yeah, I figured.

This returns incorrect results anyways.

See screenshot - source table vs. matrix with measure value

DmitryKo_0-1678131192056.png

 

@DmitryKo 

Yes you are right. Another mistake 

=
MAXX (
CALCULATETABLE (
TOPN ( 1, 'Table', 'Table'[DateTime] ),
'Date'[Date] <= MAX ( 'Date'[Date] )
),
'Table'[Status]
)

This seem to work with DESC sort order in TOPN. Thank you!

@DmitryKo 
DESC is default in TOPN. No need to add it.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.