Forum Discussion

ronaldbalza2023's avatar
ronaldbalza2023
Continued Contributor
3 years ago
Solved

COLOR FORMATTING - SWITCH STATEMENT

Hi everyone. I am using the switch statement for color formatting with this line of code. However, when it reaches to the same target amount, it doesn't excute the right formatting. What the code does it that if the actual meets or exceeds the target, the bg color will turn into green, if the actual meets atleast 90% of the target color will turn into yellow. the rest will turn into color red.

Now, the actual meets the exact target, the background supposedly turn into green but it doesn't. What did I missed? Thanks in advance.

% Productivity vs KPI Formmating = 
    SWITCH(
        TRUE(),
        [Productivity Percentage]>=[Productivity KPI],"#6aa84f", //GREEN
        [Productivity Percentage]>[Productivity KPI] * .90,"#feda03", //YELLOW 
        "#bf211e" //RED
    )



 

  • Hey ronaldbalza2023 ,

    from my perspective, the formatting measure works perfectly. I use exactly your definition, and this allows me to create the below table visual:

    I created two very simple measures to represent the measures that are used inside the formatting measure:

    Productivity Percentage = AVERAGE( 'Table'[Actual] ) 
    Productivity KPI = AVERAGE( 'Table'[Target] )

    and this one just to create a check inside the table:

    Productivity Percentage 90 = AVERAGE( 'Table'[Target] ) * .9

     

    Maybe, you can create a table showing the measures used inside the formatting measure. Be aware that this value (formatted by the UI) 55.0% does not equal the value 0.5501.

    You need to format (adjust) the measure inside the DAX statement regarding the precision. 

     

    Hopefully, this provides some ideas on how to tackle your challenge.

     

    Regards,
    Tom

1 Reply

  • Hey ronaldbalza2023 ,

    from my perspective, the formatting measure works perfectly. I use exactly your definition, and this allows me to create the below table visual:

    I created two very simple measures to represent the measures that are used inside the formatting measure:

    Productivity Percentage = AVERAGE( 'Table'[Actual] ) 
    Productivity KPI = AVERAGE( 'Table'[Target] )

    and this one just to create a check inside the table:

    Productivity Percentage 90 = AVERAGE( 'Table'[Target] ) * .9

     

    Maybe, you can create a table showing the measures used inside the formatting measure. Be aware that this value (formatted by the UI) 55.0% does not equal the value 0.5501.

    You need to format (adjust) the measure inside the DAX statement regarding the precision. 

     

    Hopefully, this provides some ideas on how to tackle your challenge.

     

    Regards,
    Tom