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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
deanbland
Helper III
Helper III

How to flag status change

Hi, 

 

I have a dataset like this: 

 

IDDateStatus
ID122/08/2020Open
ID222/08/2020Open
ID322/08/2020 
ID122/09/2020Closed
ID222/09/2020Open

 

I am wanting to create a measure or calculated column that assesses this change, and assigns a 1 to where the status has changed, per month. Some ID's haven't been assigned a status so there are three variables in this (null, Open, Closed) . 

 

I have tried a couple of ways but they always calculate the blank status as a change ! 

 

Any help is appreciated - thanks!

1 ACCEPTED SOLUTION

Hi @deanbland ,

 

Please try the following formula:

 

Column = 
var PreDate = 
    MAXX(
        FILTER(
            'Table',
            'Table'[Date] < EARLIER('Table'[Date])
            && 'Table'[ID] = EARLIER('Table'[ID])
        ),
        'Table'[Date]
    )
var PD_Status = 
    CALCULATE(
        MAX('Table'[Status]),
        FILTER(
            'Table',
            'Table'[Date] = PreDate 
            && 'Table'[ID] = EARLIER('Table'[ID])
        )
    )
return 
    IF( PD_Status = BLANK() || PD_Status = 'Table'[Status], 0, 1 )

image.png 

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
mahoneypat
Microsoft Employee
Microsoft Employee

Worked on this at same time.  Here is a measure expression you can try too.

 

 

 

StatusChange =
VAR latestdate =
    MAX ( 'Status'[Date] )
VAR lateststatus =
    CALCULATE ( MIN ( 'Status'[Status] ), 'Status'[Date] = latestdate )
VAR prevdate =
    CALCULATE ( MAX ( 'Status'[Date] ), 'Status'[Date] < latestdate )
VAR prevstatus =
    CALCULATE ( MIN ( 'Status'[Status] ), 'Status'[Date] = prevdate )
RETURN
    IF ( ISBLANK ( prevstatus ) || prevstatus = lateststatus, "N", "Y" )

 

Pat

 

mahoneypat_0-1628435201617.png





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Fowmy
Super User
Super User

@deanbland 

I added a new column, also add one more record to check the scenario in the sample data.

Change = 
INT(
    COUNTROWS(
        FILTER(
            Table2,
            Table2[ID] = EARLIER(Table2[ID]) && FORMAT(Table2[Date],"yymm") = FORMAT(EARLIER(Table2[Date]),"yymm") && Table2[Status] <> BLANK()
        )
    )>1
)
    

Fowmy_0-1628434837605.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Hi @Fowmy , 

 

I have tried your suggestion and it isn't picking up the status changes. The highlighted column on the right shows the output from the DAX you provided, which is not the expected outcome as the status change from Open to Close should have been marked. 

 

Table COntent.png

 

DateIDStatusStatus Change
28/06/2021RID17Open0
05/07/2021RID17Closed1
02/08/2021RID17Closed0

 

Above shows an exact cut from the data, only including the columns needed and filtered on the example in the picture. The end column is the expected output. How would I go about editing your DAX to provide this outcome? 

 

Thanks for all your help so far!

Hi @deanbland ,

 

Please try the following formula:

 

Column = 
var PreDate = 
    MAXX(
        FILTER(
            'Table',
            'Table'[Date] < EARLIER('Table'[Date])
            && 'Table'[ID] = EARLIER('Table'[ID])
        ),
        'Table'[Date]
    )
var PD_Status = 
    CALCULATE(
        MAX('Table'[Status]),
        FILTER(
            'Table',
            'Table'[Date] = PreDate 
            && 'Table'[ID] = EARLIER('Table'[ID])
        )
    )
return 
    IF( PD_Status = BLANK() || PD_Status = 'Table'[Status], 0, 1 )

image.png 

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Does something like this work if you have two seperate tables.... I have two imports. One from the previous week and one from this week. And I need to find the change between the two tables 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

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.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.