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
rsreepathi
Frequent Visitor

Return the latest date based on status change

Hi,

 

This is my first post, below is my data and this is what I want to achieve:

 

for each ID->find the latest status-> corresponding date field

 

NameIDdatestatus
setting 1293/9/2021 1.42 PM0
setting 1293/9/2021 1.43 PM0
setting 1293/9/2021 1.44 PM0
setting 1293/9/2021 1.45 PM1
setting 1293/9/2021 1.46 PM1
setting 1293/9/2021 1.47 PM1
setting 1293/9/2021 1.48 PM1
setting 1293/9/2021 1.49 PM1
setting 2303/9/2021 1.42 PM0
setting 2303/9/2021 1.43 PM0
setting 2303/9/2021 1.44 PM0
setting 2303/9/2021 1.45 PM1
setting 2303/9/2021 1.46 PM1
setting 2303/9/2021 1.47 PM0
setting 2303/9/2021 1.48 PM0
setting 2303/9/2021 1.49 PM0
setting 2303/9/2021 1.50 PM1
setting 2303/9/2021 1.51 PM0

 

Based on the above data for setting 1-> the latest state change is from 0 to 1-> date field to return is 3/9/2021 1.45 PM

similarly for setting 2 -> the latest state change is from 1 to 0 -> date field to return is 3/9/2021 1.50 PM

 

data to extract

setting 1->3/9/2021 1.45PM

setting 2 ->3/9/2021 1.50PM

 

I am able to get the state to go from either 0 to 1 or 1 to 0, any help would be appreciated.

 

Thanks 

RS

1 ACCEPTED SOLUTION
jameszhang0805
Resolver IV
Resolver IV

@rsreepathi 
Please try the below code:

jameszhang0805_0-1615449809796.png

LatestDate = 
VAR _Table =
    ADDCOLUMNS (
        SUMMARIZE ( 'Data', Data[Name], Data[date], Data[status] ),
        "@PreviousStatus",
            VAR _PreviousDate =
                CALCULATE (
                    MAX ( 'Data'[date] ),
                    ALL ( 'Data' ),
                    'Data'[date] < EARLIER ( Data[date] )
                )
            VAR _PreviousStatus =
                CALCULATE (
                    MAX ( 'Data'[status] ),
                    ALLEXCEPT ( Data, 'Data'[Name], Data[date] ),
                    'Data'[date] = _PreviousDate
                )
            RETURN
                _PreviousStatus
    )
VAR _FilteredTable =
    FILTER ( _Table, 'Data'[status] <> [@PreviousStatus] && 'Data'[status] = 1 )
RETURN
    IF( HASONEVALUE( Data[Name] ) , CALCULATE ( MAX ( 'Data'[date] ), _FilteredTable ) )       

View solution in original post

3 REPLIES 3
rsreepathi
Frequent Visitor

thank you @jameszhang0805 that worked!

jameszhang0805
Resolver IV
Resolver IV

@rsreepathi 
Please try the below code:

jameszhang0805_0-1615449809796.png

LatestDate = 
VAR _Table =
    ADDCOLUMNS (
        SUMMARIZE ( 'Data', Data[Name], Data[date], Data[status] ),
        "@PreviousStatus",
            VAR _PreviousDate =
                CALCULATE (
                    MAX ( 'Data'[date] ),
                    ALL ( 'Data' ),
                    'Data'[date] < EARLIER ( Data[date] )
                )
            VAR _PreviousStatus =
                CALCULATE (
                    MAX ( 'Data'[status] ),
                    ALLEXCEPT ( Data, 'Data'[Name], Data[date] ),
                    'Data'[date] = _PreviousDate
                )
            RETURN
                _PreviousStatus
    )
VAR _FilteredTable =
    FILTER ( _Table, 'Data'[status] <> [@PreviousStatus] && 'Data'[status] = 1 )
RETURN
    IF( HASONEVALUE( Data[Name] ) , CALCULATE ( MAX ( 'Data'[date] ), _FilteredTable ) )       
amitchandak
Super User
Super User

@rsreepathi , with name this measure should work

calculate(max(table[date]), filter(Table, Table[status]=1))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.