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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Anonymous
Not applicable

Flag Final Status Changing in Time - Based on value change in time, mark only final expected one

I need to set flag on date when final change in status of trip happened. I am getting daily information on trips that will happen in future, however already booked trips can be cancelled. To understand market, I want to have for each Trip and Date only final effective day flagged on new column "Real Book Day"

 

Data set here >> 

 

flag_final_status_change.PNG

 

Thanks a lot for help!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

You can add two calculated columns to achieve your requirement: (first formula is used to find out records whose status changed to 'book', the second one used to find out the last one)

Status Change = 
VAR prevDate =
    CALCULATE (
        MAX ( T2[Report_Date] ),
        FILTER (
            ALLSELECTED ( T2 ),
            [Trip_Id] = EARLIER ( T2[Trip_Id] )
                && [Report_Date] < EARLIER ( [Report_Date] )
        )
    )
VAR currStatus =
    LOOKUPVALUE (
        T2[Trip_Status],
        T2[Trip_Id], [Trip_Id],
        T2[Report_Date], [Report_Date]
    )
VAR prevStatus =
    LOOKUPVALUE (
        T2[Trip_Status],
        T2[Trip_Id], [Trip_Id],
        T2[Report_Date], prevDate
    )
RETURN
    IF ( prevStatus = 1 && currStatus IN { 2, 3 }, 1 )

Real Book Day =
VAR _rank =
    CALCULATE (
        COUNT ( T2[Status Changes] ) + 1,
        FILTER (
            ALLSELECTED ( T2 ),
            [Trip_Id] = EARLIER ( T2[Trip_Id] )
                && [Report_Date] > EARLIER ( T2[Report_Date] )
        )
    )
RETURN
    IF ( _rank = 1, [Status Changes] )

Regards,

Xiaoxin Sheng

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Anonymous ,

You can add two calculated columns to achieve your requirement: (first formula is used to find out records whose status changed to 'book', the second one used to find out the last one)

Status Change = 
VAR prevDate =
    CALCULATE (
        MAX ( T2[Report_Date] ),
        FILTER (
            ALLSELECTED ( T2 ),
            [Trip_Id] = EARLIER ( T2[Trip_Id] )
                && [Report_Date] < EARLIER ( [Report_Date] )
        )
    )
VAR currStatus =
    LOOKUPVALUE (
        T2[Trip_Status],
        T2[Trip_Id], [Trip_Id],
        T2[Report_Date], [Report_Date]
    )
VAR prevStatus =
    LOOKUPVALUE (
        T2[Trip_Status],
        T2[Trip_Id], [Trip_Id],
        T2[Report_Date], prevDate
    )
RETURN
    IF ( prevStatus = 1 && currStatus IN { 2, 3 }, 1 )

Real Book Day =
VAR _rank =
    CALCULATE (
        COUNT ( T2[Status Changes] ) + 1,
        FILTER (
            ALLSELECTED ( T2 ),
            [Trip_Id] = EARLIER ( T2[Trip_Id] )
                && [Report_Date] > EARLIER ( T2[Report_Date] )
        )
    )
RETURN
    IF ( _rank = 1, [Status Changes] )

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

Xiaoxin, thank you very much, solution looks good. But i am getting out of memory error message in First formula: There's not enough memory to complete this operation. Please try again later when there may be more memory available. 

 

My tables are quite large (700k lines every day for last year). Any chance to optimize, that it will itenerate and write by Trip Id and From rather then try to calculate in memory at once?

 

Anonymous
Not applicable

HI @Anonymous ,

My formula contains a few looping calculations so it may spend more system resources. If it iterates on huge amount of records, it may cause the memory issue.

You can try to add an index field to your table and use the index and 'status change' to find out 'real book day':

Real Book Day =
VAR _max =
    CALCULATE (
        MAX ( T2[Index] ),
        FILTER (
            ALLSELECTED ( T2 ),
            [Trip_Id] = EARLIER ( T2[Trip_Id] )
                && [Status Changes] = 1
        )
    )
RETURN
    IF ( T2[Index] = _max, [Status Changes] )

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.