Forum Discussion
Conditionally Format a Card with Variable Hex Codes
- 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 ) )
Hello bernate
Try this Measure
TrainingColorHex =
VAR SelectedLocation = SELECTEDVALUE('Location Table'[Location])
VAR TrainingComplete = [Training Complete %] -- Your dynamic % measure
RETURN
SWITCH(TRUE(),
SelectedLocation = "Alabama" && TrainingComplete < 97, "#E4080A",
SelectedLocation = "Alabama" && TrainingComplete >= 97 && TrainingComplete <= 103, "#7DDA58",
SelectedLocation = "Alabama" && TrainingComplete > 103, "#5DE2E7",
SelectedLocation = "Georgia" && TrainingComplete < 97, "#E4080A",
SelectedLocation = "Georgia" && TrainingComplete >= 97 && TrainingComplete <= 99.9, "#FFDE59",
SelectedLocation = "Georgia" && TrainingComplete > 99.9, "#7DDA58",
SelectedLocation = "Mississippi" && TrainingComplete < 95, "#FE9900",
SelectedLocation = "Mississippi" && TrainingComplete >= 95 && TrainingComplete < 98, "#FFECA1",
SelectedLocation = "Mississippi" && TrainingComplete >= 98 && TrainingComplete <= 102, "#7DDA58",
SelectedLocation = "Mississippi" && TrainingComplete > 102 && TrainingComplete <= 105, "#98F5F9",
SelectedLocation = "Mississippi" && TrainingComplete > 105, "#060270",
SelectedLocation = "Florida" && TrainingComplete < 97, "#E4080A",
SelectedLocation = "Florida" && TrainingComplete >= 97 && TrainingComplete <= 99, "#FFDE59",
SelectedLocation = "Florida" && TrainingComplete > 99 && TrainingComplete <= 103, "#7DDA58",
SelectedLocation = "Florida" && TrainingComplete > 103, "#5DE2E7",
"#FFFFFF" -- default white color if no match
)
Apply This Measure to the Card's Background or Data Label Color
- bernate1 year agoHelper III
Thank you for this option, it worked with a normal measure but not with a parameter.