Forum Discussion
bernate
1 year agoHelper III
Conditionally Format a Card with Variable Hex Codes
Hello, I am trying to conditionally format a card visual to display a color associated with certain rules. I have 2 tables: Location and Training Complete. Location Table: Location Alabama...
- 1 year ago
Hi bernate
Each measure in a field variable needs to be conditionally formatted individually as you select a measure in the slicer. Alternatively, you can write a measure that detects what measure is being selected and return hexadecimal values based on that. Try:
Training MTD % Color = VAR _TrainingOrder = SELECTEDVALUE ( Training[Order] ) -- 0 = Alabama, 1 = Georgia, 2 = Mississippi, 3 = Florida VAR _MTDMeasure = SWITCH ( _TrainingOrder, 0, [Alabama MTD Training %], 1, [Georgia MTD Training %], 2, [Mississippi MTD Training %], 3, [Florida MTD Training %] ) RETURN SWITCH ( _TrainingOrder, 0, // --- Alabama --- SWITCH ( TRUE (), _MTDMeasure < 97, "#E4080A", // Red _MTDMeasure <= 103, "#7DDA58", // Green _MTDMeasure > 103, "#5DE2E7" // Blue ), 1, // --- Georgia --- SWITCH ( TRUE (), _MTDMeasure < 97, "#E4080A", // Red _MTDMeasure <= 99.9, "#7DDA58", // Green _MTDMeasure <= 100, "#FFDE59", // Yellow _MTDMeasure > 100, "#7DDA58" // Green again ), 2, // --- Mississippi --- SWITCH ( TRUE (), _MTDMeasure < 95, "#FE9900", // Orange _MTDMeasure < 98, "#FFDE59", // Yellow _MTDMeasure <= 102, "#7DDA58", // Green _MTDMeasure <= 105, "#98F5F9", // Light Blue _MTDMeasure > 105, "#060270" // Dark Blue ), 3, // --- Florida --- SWITCH ( TRUE (), _MTDMeasure < 97, "#E4080A", // Red _MTDMeasure <= 99, "#FFDE59", // Yellow _MTDMeasure <= 103, "#7DDA58", // Green _MTDMeasure > 103, "#5DE2E7" // Blue ) )
amitchandak
1 year agoSuper User
bernate , In case you want field parameter to work with conditional formatting use
Field Parameters- Conditional Formatting: https://amitchandak.medium.com/field-parameters-conditional-formatting-517aacc23fdf
Also, you can use a looped Switch and if
Also note percent is displayed as *100. Measn .25 is displayed as 25% (when you choose format as %)