The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event! Join us in Stockholm, Sweden from September 24-27, 2024.
2-for-1 sale on June 20 only!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
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
What I want:
Mark only the rows where the status is different than yesterday.
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
|
Solved! Go to Solution.
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))
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().
Expertise = List.Accumulate( {Days as from Today}, {Skills and Knowledge}, (Current, Everyday) => Current & Day.LeanAndPractise(Everyday) ) |
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))
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!
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the June 2024 Power BI update to learn about new features.
User | Count |
---|---|
95 | |
93 | |
85 | |
68 | |
65 |
User | Count |
---|---|
241 | |
124 | |
120 | |
81 | |
79 |