Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
LordArcturus
New Member

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.

1 ACCEPTED SOLUTION

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

View solution in original post

2 REPLIES 2
vicky_
Super User
Super User

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. 

 

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

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.