Forum Discussion

LordArcturus's avatar
LordArcturus
New Member
2 years ago
Solved

Switch color hierarchy <- Is it possible?

Hi!

I made this code that will change colors on my dashboard depending whether the value in question is negative or positive, but I did also want to have a third color(orange), which would signify that the value is not to far off neagative: 
Bounce Rate Color Leaflet BE = SWITCH(

    TRUE(),

    [Bounce Rate (Up to Current Month) Leaflet BE] > [Bounce Rate Leaflet BE], "#00FF00", --green

    [Bounce Rate (Up to Current Month) Leaflet BE] < [Bounce Rate Leaflet BE], "#FF0000",

    AND([Bounce Rate Dif Current year and past year Leaflet BE] >= 0.01, [Bounce Rate Dif Current year and past year Leaflet BE] <= 1), "#FFA500", --orange

    "#000000"

)

 

but of course the orange won't work since there is no hierarchy amongst the different sections of the coding, so the green and the red always override the orange. With this in mind, what would be the best solution to introducing this third color?
Thank you very much for your time.

  • Thank you. 

    At the end the best solution I found was to convert the colors into variables

    Cart Additions Color RP BE = Var greenbound = [Cart Additions YTD LY RP BE]*(1+[Percentage change])
    Var redbound = [Cart Additions YTD LY RP BE]*(1-[Percentage change])

    VAR PercentageTargetAchieved = [Cart Additions RP BE]
    VAR Result =
    IF(PercentageTargetAchieved = 0, [Gray],
        SWITCH(TRUE(),
                    PercentageTargetAchieved > greenbound,[Green Color],
                PercentageTargetAchieved < redbound,[Red Color],
                [Orange]
        ))
    RETURN
    Result

2 Replies

  • Can you try switch up the order of the switch statements - i.e 

     

    Bounce Rate Color Leaflet BE = SWITCH(
        TRUE(),
        AND([Bounce Rate Dif Current year and past year Leaflet BE] >= 0.01, [Bounce Rate Dif Current year and past year Leaflet BE] <= 1), "#FFA500", --orange
        //-- green
        //-- orange
    )

    so that the orange will evaluate first before it meets the green / orange conditions?

    There are also ways to format based on the level of the heirarchy - you can add additional conditions ISFILTERED or ISINSCOPE to determine the current level.

    Otherwise, you will need to go back and change the [Bounce Rate Leaflet BE] measures to either return BLANK / some other value depending on the heirarchy levels. 

     

    • LordArcturus's avatar
      LordArcturus
      New Member

      Thank you. 

      At the end the best solution I found was to convert the colors into variables

      Cart Additions Color RP BE = Var greenbound = [Cart Additions YTD LY RP BE]*(1+[Percentage change])
      Var redbound = [Cart Additions YTD LY RP BE]*(1-[Percentage change])

      VAR PercentageTargetAchieved = [Cart Additions RP BE]
      VAR Result =
      IF(PercentageTargetAchieved = 0, [Gray],
          SWITCH(TRUE(),
                      PercentageTargetAchieved > greenbound,[Green Color],
                  PercentageTargetAchieved < redbound,[Red Color],
                  [Orange]
          ))
      RETURN
      Result