Forum Discussion

bernate's avatar
bernate
Helper III
1 year ago
Solved

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...
  • danextian's avatar
    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
                )
        )