I have a table in PowerBI.
I need to create a custom column, that detects this flag changes.
Output should look like -
e.g= EID 3 changed flag in 2020. thats why new flag is set to 1. this is a sample , I have multiple eids.
I have a table in PowerBI.
I need to create a custom column, that detects this flag changes.
Output should look like -
e.g= EID 3 changed flag in 2020. thats why new flag is set to 1. this is a sample , I have multiple eids.
I'd recommend checking out this post to see different approaches for looking up previous flags.
One particular implementation might look like this (but there are lots of other ways to do the same thing):
New Flag =
VAR CurrYear = Table1[Year]
VAR PrevYear =
CALCULATE (
MAX ( Table1[Year] ),
ALLEXCEPT ( Table1, Table1[EID] ),
Table1[Year] < CurrYear
)
VAR PrevFlag =
CALCULATE (
SELECTEDVALUE ( Table1[Flag] ),
ALLEXCEPT ( Table1, Table1[EID] ),
Table1[Year] = PrevYear
)
RETURN
IF ( ISBLANK ( PrevYear ) || Table1[Flag] = PrevFlag, 0, 1 )
This finds the previous year, if it exists, using a max (in case the years aren't contiguous), then looks up the flag for that particular year, and finally checks if the current flag differs from the previous flag (if there is a previous flag).