Forum Discussion

Silvard's avatar
Silvard
Resolver I
1 year ago
Solved

Overwriting Color conditional formatting

I would like to apply Color conditional formatting to a visual dynamically between 40 different measures.   How can I do this with a calculation group and specifically using DAX expressions that on...
  • v-kpoloju-msft's avatar
    v-kpoloju-msft
    1 year ago

    Hi  Silvard,

    You're correct. You cannot directly place a calculation item into the fx field for conditional formatting, as it only accepts measures, not calculation items. This is a current platform limitation.

    To work around this, use SELECTEDMEASURE() in a helper measure that can be referenced in the fx field. Create a helper measure that references SELECTEDMEASURE(), reflecting the measure selected via your calculation group. Then, use that measure in your fx conditional formatting logic.

    Additionally, you can create a calculation group for your measures. Use Tabular Editor to define a calculation group (e.g., "Metric Selector") and add 40 calculation items, one per measure.

    Dax Measure for Metric Selector:

    Name: Sales Amount
    Expression: [Sales Amount]
    

    Dax Measure For Color Formatting:

    Color Formatting Measure = 
    VAR _current = SELECTEDMEASURE()
    VAR _previous = CALCULATE(_current, SAMEPERIODLASTYEAR('Date'[Date]))
    RETURN 
        IF(
            _current > _previous, 
            "#00FF00",  // Green
            IF(
                _current < _previous,
                "#FF0000",  // Red
                "#808080"   // Grey for no change
            )
        )
    

    Please ensure that your data model includes a valid 'Date' table marked as such to enable the SAMEPERIODLASTYEAR function to operate correctly.

    Apply Conditional Formatting in Visual: Once you have a measure that returns color values, select your visual. Navigate to the Format pane > Data colors (or Font color), and click the fx button. Choose Format by: Field value, then select the Color Formatting Measure.

    This will dynamically apply color formatting based on the chosen measure, displaying green if the value is higher than last year, and red if it is lower.


    If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

    Thank you for using Microsoft Community Forum.