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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Paulyeo11
Impactful Individual
Impactful Individual

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
v-stephen-msft
Community Support
Community Support

Hi @Paulyeo11 ,

 

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
v-stephen-msft
Community Support
Community Support

Hi @Paulyeo11 ,

 

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.

Hi Stephen

Thank you very much

Paul

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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