Forum Discussion
cqueiroz2222
1 year agoHelper I
Adding an IF condition to a Measure
Hello, I am trying to reply an Excel Rule into DAX Measure The idea is: When Result < 0, sum Result + Last Month C/C (superior line), otherwise, just reply the result So just reply the result wh...
Anonymous
1 year agoNot applicable
Hi cqueiroz2222 ,
I create a table as you mentioned.
Then I think you can create a calculated column.
C/C =
VAR _Current = 'Table'[Result]
VAR _Previous =
CALCULATE (
SUM ( 'Table'[Result] ),
FILTER ( 'Table', 'Table'[Month] < EARLIER ( 'Table'[Month] ) )
)
RETURN
_Current + COALESCE ( _Previous, 0 )
I also think you can create two measures and here are the DAX codes.
Result_Color = IF(MAX('Table'[Result])<0,"Red","Black")C/C_Color = IF(MAX('Table'[C/C])<0,"Red","Black")
Next make them into Conditional formatting.
Finally you will get what you want.
Best Regards
Yilong Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
cqueiroz2222
1 year agoHelper I
But this last line isnt respecting the rule: if the last month result's be positive, just reply current month result
- Angith_Nair1 year agoContinued Contributor
You can try the below dax:
C/C = VAR _Current = 'Table'[Result] VAR _MaxMonth = MAXX(ALL('Table'), 'Table'[Month]) VAR _Previous = CALCULATE ( SUM ( 'Table'[Result] ), FILTER ( 'Table', 'Table'[Month] < EARLIER ( 'Table'[Month] ) ) ) RETURN IF ( 'Table'[Month] = _MaxMonth && _Current < 0, _Current, _Current + COALESCE ( _Previous, 0 ) )- cqueiroz22221 year agoHelper I