Forum Discussion
Conditional Formatting with DAX
- 4 years ago
Hi Anonymous ,
Let the min in red and max in green, and if "Actual" value is zero, then this period in red, which result basd on [sales_] of each rows.
Please try this code to do that:
Measured = VAR _s = FILTER ( SUMMARIZE ( ALLSELECTED ( 'Data Table'[Year] ), [Year], "Sale", IF ( COUNTROWS ( FILTER ( 'Data Table', 'Data Table'[Version] = "Actual" && [Sales] = 0 ) ) > 0, BLANK (), [Sales_] ) ), [Sale] > 0 ) VAR _ss = FILTER ( SUMMARIZE ( CALCULATETABLE ( 'Data Table', ALLSELECTED ( 'Data Table'[Year] ), 'Data Table'[Quarter] <> "FY" ), [Year], "Sale", IF ( COUNTROWS ( FILTER ( 'Data Table', 'Data Table'[Version] = "Actual" && [Sales] = 0 ) ) > 1, 0, [Sales_] ) ), [Sale] > 0 ) VAR _max = IF ( SELECTEDVALUE ( 'Data Table'[Quarter] ) = "FY", MAXX ( TOPN ( 1, _ss, [Sale], DESC ), [Year] ), MAXX ( TOPN ( 1, _s, [Sale], DESC ), [Year] ) ) VAR _min = IF ( SELECTEDVALUE ( 'Data Table'[Quarter] ) = "FY", MAXX ( TOPN ( 1, _ss, [Sale], ASC ), [Year] ), MAXX ( TOPN ( 1, _s, [Sale], ASC ), [Year] ) ) RETURN SWITCH ( SELECTEDVALUE ( 'Data Table'[Year] ), _max, "green", _min, "red", "black" )Result:
Pbix in the end you can refer.
Best Regards
Community Support Team _ chenwu zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous ,
Let the min in red and max in green, and if "Actual" value is zero, then this period in red, which result basd on [sales_] of each rows.
Please try this code to do that:
Measured =
VAR _s =
FILTER (
SUMMARIZE (
ALLSELECTED ( 'Data Table'[Year] ),
[Year],
"Sale",
IF (
COUNTROWS (
FILTER ( 'Data Table', 'Data Table'[Version] = "Actual" && [Sales] = 0 )
) > 0,
BLANK (),
[Sales_]
)
),
[Sale] > 0
)
VAR _ss =
FILTER (
SUMMARIZE (
CALCULATETABLE (
'Data Table',
ALLSELECTED ( 'Data Table'[Year] ),
'Data Table'[Quarter] <> "FY"
),
[Year],
"Sale",
IF (
COUNTROWS (
FILTER ( 'Data Table', 'Data Table'[Version] = "Actual" && [Sales] = 0 )
) > 1,
0,
[Sales_]
)
),
[Sale] > 0
)
VAR _max =
IF (
SELECTEDVALUE ( 'Data Table'[Quarter] ) = "FY",
MAXX ( TOPN ( 1, _ss, [Sale], DESC ), [Year] ),
MAXX ( TOPN ( 1, _s, [Sale], DESC ), [Year] )
)
VAR _min =
IF (
SELECTEDVALUE ( 'Data Table'[Quarter] ) = "FY",
MAXX ( TOPN ( 1, _ss, [Sale], ASC ), [Year] ),
MAXX ( TOPN ( 1, _s, [Sale], ASC ), [Year] )
)
RETURN
SWITCH (
SELECTEDVALUE ( 'Data Table'[Year] ),
_max, "green",
_min, "red",
"black"
)
Result:
Pbix in the end you can refer.
Best Regards
Community Support Team _ chenwu zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
I was finally able to make this work, so thank you!! I had to make a couple of changes for some formatting differences between my file and the sample I shared but finally got it to work.
Is there any reason a similar measure should not work for a metric that is coming from a calculated column? Sales and Volume are an original part of my data source. I also want to view sales per pound, so I created a calculated column for this new metric. I am wanting to show the same type of conditional formatting for this metric, but I cannot get FY22 to be excluded from the formatting. The quarters are formatting correctly.
- Anonymous4 years agoNot applicable
I was able to fix it. I needed to insert an additional filter in the DAX for the calculated measure for the conditional formatting measure to work.
All problems are solved. Thanks so much for your help!!