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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
cinderelly678
Frequent Visitor

Help Flagging Status Change

I want to have a measure that will display 1 when a status has changed, and 0 when the status is the same as yesterday's value. My data set is rather large, so I want to avoid using a calculated column if possible.

 

I feel like I'm so close to having the right DAX, but this measure is not giving me the result I am looking for. 

 

 

Change Status Flag = 
INT (
    COUNTROWS (
        FILTER (
            'Table',
            'Table'[Key]
                = EARLIER ( 'Table'[Key] )
                && 'Table'[Status]
                    <> EARLIER ( 'Table'[Status] )
                && 'Table'[Snapshot Date]
                    = EARLIER ( 'Table'[Snapshot Date] )
        )
    ) > 0
)

 

 

 

What I'm getting - 
value set to 1 even though the status from the previous day hasn't changed

ellywinters_0-1693008982149.png

 

What I want:

Mark only the rows where the status is different than yesterday.

ellywinters_1-1693009029019.png

 

Could anyone help me out with the DAX to accomplish this? Thank you in advance for your help.

 

Attached is my sample data. 

 

Snapshot DateKeyStatus
8/25/2023 0:00ApplesShipped
8/24/2023 0:00ApplesShipped
8/23/2023 0:00ApplesShipped
8/22/2023 0:00ApplesShipped
8/21/2023 0:00ApplesShipped
8/20/2023 0:00ApplesShipped
8/19/2023 0:00ApplesShipped
8/18/2023 0:00ApplesShipped
8/17/2023 0:00ApplesOrdered
8/25/2023 0:00OrangesShipped
8/24/2023 0:00OrangesShipped
8/23/2023 0:00OrangesShipped
8/22/2023 0:00OrangesShipped
8/21/2023 0:00OrangesShipped
8/20/2023 0:00OrangesShipped
8/19/2023 0:00OrangesShipped
8/18/2023 0:00OrangesShipped
8/17/2023 0:00OrangesOrdered
1 ACCEPTED SOLUTION
foodd
Community Champion
Community Champion

Use the following DAX to create the column:

 

Change Status Flag = 
VAR CurrentDate = 'Table'[Snapshot Date]
VAR CurrentKey = 'Table'[Key]
VAR CurrentStatus = 'Table'[Status]
VAR PreviousStatus =
    CALCULATE(
        FIRSTNONBLANK('Table'[Status], 1),
        FILTER(
            'Table',
            'Table'[Snapshot Date] = CurrentDate - 1 &&
            'Table'[Key] = CurrentKey
        )
    )
RETURN IF(ISBLANK(PreviousStatus), 0, IF(CurrentStatus <> PreviousStatus, 1, 0))

 

 

foodd_0-1693013413420.png

 

View solution in original post

5 REPLIES 5
ThxAlot
Super User
Super User

So far, few users opt for window functions; perhaps few have profound comprehension of them.

 

I hope the window functions are more performant in such scenarios than "old school" FILTER().

 

ThxAlot_0-1693076840736.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



Ashish_Mathur
Super User
Super User

Hi,

Please find attached the PBI file.

Hope this helps.

Ashish_Mathur_0-1693030062536.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
foodd
Community Champion
Community Champion

Use the following DAX to create the column:

 

Change Status Flag = 
VAR CurrentDate = 'Table'[Snapshot Date]
VAR CurrentKey = 'Table'[Key]
VAR CurrentStatus = 'Table'[Status]
VAR PreviousStatus =
    CALCULATE(
        FIRSTNONBLANK('Table'[Status], 1),
        FILTER(
            'Table',
            'Table'[Snapshot Date] = CurrentDate - 1 &&
            'Table'[Key] = CurrentKey
        )
    )
RETURN IF(ISBLANK(PreviousStatus), 0, IF(CurrentStatus <> PreviousStatus, 1, 0))

 

 

foodd_0-1693013413420.png

 

This works brilliantly and is very handy to have in the arsenal. Thank you so much @foodd , you made my Friday night!

I take Kudos anytime.  Glad that I could help!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

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