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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
Anonymous
Not applicable

How to write traffic light script ?

Hi All

Today i have try to modify the below table report , and when i put back the Variance % , the traffic light colour reset , and i need to set up again. Since i have many table , and i want to change the traffic light from Rule base to script base :-

if Variance >50% Yellor Color

if Variance >10% and <50% Green Color

if Variance <10% Red Color

Hope that some one can help me write the script.

 

My PBIX file :-

https://www.dropbox.com/s/wml3gzffts2ak4q/preWebinarPostCal_PY_DATA%20V008%20Working%20%283%29.pbix?...

 

Paulyeo11_0-1603184454777.png

 

1 ACCEPTED SOLUTION
themistoklis
Community Champion
Community Champion

@Anonymous 

 

Put the following formula in a measure and then add it in the conditional formatting (using field value).

 

Background Color 1 =
VAR _variance_per_country =
    CALCULATE ( [Variance %], ALLEXCEPT ( 'order', 'order'[Customer Id] ) )
RETURN
    SWITCH (
        TRUE (),
        _variance_per_country < 0.2, "#D64550",
        _variance_per_country < 0.5, "#E8D166",
        _variance_per_country <= 10, "#79FF00",
        "#00000"
    )

 

View solution in original post

2 REPLIES 2
themistoklis
Community Champion
Community Champion

@Anonymous 

 

Put the following formula in a measure and then add it in the conditional formatting (using field value).

 

Background Color 1 =
VAR _variance_per_country =
    CALCULATE ( [Variance %], ALLEXCEPT ( 'order', 'order'[Customer Id] ) )
RETURN
    SWITCH (
        TRUE (),
        _variance_per_country < 0.2, "#D64550",
        _variance_per_country < 0.5, "#E8D166",
        _variance_per_country <= 10, "#79FF00",
        "#00000"
    )

 

Anonymous
Not applicable

Hi Sir

Thank you so much , it work fine now .

Paulyeo11_0-1603188445640.png

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.