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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

How to have Dynamic black ground color expression ?

Hi All

 

I have below script work fine.

 

Background Color 1 =
VAR _variance_per_country =
CALCULATE ( [Variance %], ALLEXCEPT ( 'TABLE', 'TABLE'[BRAND_C] ) )
RETURN
SWITCH (
TRUE (),
_variance_per_country < 0.01, "#D64550",
_variance_per_country < 0.2, "#E8D166",
_variance_per_country <= 10, "#79FF00",
"#00000"
)
 
Only issue is BRAND_C , which is not dynmaic ,  meaning i need to create many similar expression for SEGMENT , SALES , etc.
 
Background Color 1 =
VAR _variance_per_country =
CALCULATE ( [Variance %], ALLEXCEPT ( 'TABLE', 'TABLE'[SEGMENT] ) )
RETURN
SWITCH (
TRUE (),
_variance_per_country < 0.01, "#D64550",
_variance_per_country < 0.2, "#E8D166",
_variance_per_country <= 10, "#79FF00",
"#00000"
)
 
Background Color 1 =
VAR _variance_per_country =
CALCULATE ( [Variance %], ALLEXCEPT ( 'TABLE', 'TABLE'[SALES_PEOPLE] ) )
RETURN
SWITCH (
TRUE (),
_variance_per_country < 0.01, "#D64550",
_variance_per_country < 0.2, "#E8D166",
_variance_per_country <= 10, "#79FF00",
"#00000"
)
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

For having dynamic background color expression, you just use [Variance %] instead of 

CALCULATE ( [Variance %], ALLEXCEPT ( 'TABLE', 'TABLE'[BRAND_C] ) ).

 

And your switch expression may have a little problem.

 

The revised complete expression is as follows:

 

Background Color 1 =
VAR _variance_per_country =
[Variance %]
RETURN
SWITCH (
TRUE (),
_variance_per_country < 0.01 && _variance_per_country >= 0, "#D64550",
_variance_per_country < 0.2 && _variance_per_country >= 0.01, "#E8D166",
_variance_per_country <= 10 && _variance_per_country >=0.2, "#79FF00",
"#00000"
)
 
10.png
 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Anonymous ,

 

For having dynamic background color expression, you just use [Variance %] instead of 

CALCULATE ( [Variance %], ALLEXCEPT ( 'TABLE', 'TABLE'[BRAND_C] ) ).

 

And your switch expression may have a little problem.

 

The revised complete expression is as follows:

 

Background Color 1 =
VAR _variance_per_country =
[Variance %]
RETURN
SWITCH (
TRUE (),
_variance_per_country < 0.01 && _variance_per_country >= 0, "#D64550",
_variance_per_country < 0.2 && _variance_per_country >= 0.01, "#E8D166",
_variance_per_country <= 10 && _variance_per_country >=0.2, "#79FF00",
"#00000"
)
 
10.png
 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi Stephen

Thank you very much

Paul

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors