Forum Discussion
Compare values with if statement
To achieve it in DAX, try this code NewColumn =
IF(
Table1[ID] = EARLIER(Table1[ID]),
IF(
Table1[Grade] > EARLIER(Table1[Grade]),
1,
0
),
BLANK()
)
I tried that but you cant have earlier in a function with if statement , it only works with filter function
- AbhinavJoshi3 years agoResponsive Resident
Oh I see, can you try this
NewColumn =
IF(
Table1[ID] = CALCULATE(MAX(Table1[ID]), FILTER(ALL(Table1), EARLIER(Table1[ID]) = Table1[ID])),
IF(
Table1[Grade] > CALCULATE(MAX(Table1[Grade]), FILTER(ALL(Table1), EARLIER(Table1[ID]) = Table1[ID])),
1,
0
),
BLANK()
)- ragygad3 years agoFrequent Visitor
it doesnt work.
so this is a dummy table of what i was trying to explain- AbhinavJoshi3 years agoResponsive Resident
Seeing the table helps, try this calculated column
HigherGradeFlag =
VAR CurrentID = Table1[ID]
VAR CurrentGrade = Table1[Grade]
VAR PreviousGrade =
CALCULATE (
MAX ( Table1[Grade] ),
FILTER ( Table1, Table1[ID] = CurrentID && Table1[Grade] < CurrentGrade )
)
RETURN
IF ( CurrentGrade > PreviousGrade, 1, 0 )