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
Marico
Helper IV
Helper IV

Conditionally formatting table based on slicer selection

I have a requirement where the background color of the numbers needs to be changed based on the slicer selection.

 

- If the Region is selected as East, the Postal code is less than 50 and the sales are less than 10,000 then "RED" else "GREEN"

- If the Region is selected as West, the postal code is less than 60, and the sales are less than 20,000 then "RED" else "GREEN"

 

Marico_0-1654192055398.png

Here is the link to the sample dataset: https://www.kaggle.com/datasets/rohitsahoo/sales-forecasting

 

1 ACCEPTED SOLUTION

@ghoshabhijeet Apologies for the delay in response. I got the reply for the percentage data type in this post: https://community.powerbi.com/t5/Desktop/Conditionally-formatting-values-in-a-table-based-on-slicer/...

View solution in original post

6 REPLIES 6
ghoshabhijeet
Solution Supplier
Solution Supplier

@Marico  Here is my solution. Please try this:

Create the following three measures:

Color Code EAST = 
VAR PostalCode = COUNTX(train,train[Postal Code])
VAR RSales = SUMX(train,train[Sales])

RETURN
SWITCH(
TRUE(),
AND(PostalCode < 50, RSales < 10000), "Red",
"Green")
Color Code WEST = 
VAR PostalCode = COUNTX(train,train[Postal Code])
VAR RSales = SUMX(train,train[Sales])

RETURN
SWITCH(
TRUE(),
AND(PostalCode < 60, RSales < 20000), "Red",
"Green")
Switch Color Codes =
IF (
SELECTEDVALUE ( RegionTable[Region] ) = "East",
[Color Code EAST],
[Color Code West]
)
ghoshabhijeet_0-1654199363228.png

After creating the above three measures,

1. Goto Format Visuals

2. Goto Cell elements

3. Select Sales under Apply Settings to

4. Select Background Color

5. Under Format Style, Select Field value

6. Under What field should we base this on?, Select Switch Color Codes measure

7. Click OK

Here is the result:

ghoshabhijeet_1-1654199612678.png

 

 

** If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution, so that it comes in top of the search and help others. Thank you !

Good Luck 👍

 

Hi @ghoshabhijeet 

 

Thanks for your detailed answer.

 

However, in the actual data the fields are of percentage data type. Could you please suggest how to modify the above measures in that case?

@MaricoSure, could you please share some sample data with what you are referring to as percentage data type.

 

** If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution, so that it comes in top of the search and help others. Thank you !

Good Luck 👍

 

@Marico  Could you please share some sample data with what you are referring to as percentage data type.

** If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution, so that it comes in top of the search and help others. Thank you !

Good Luck 👍

 

@ghoshabhijeet Apologies for the delay in response. I got the reply for the percentage data type in this post: https://community.powerbi.com/t5/Desktop/Conditionally-formatting-values-in-a-table-based-on-slicer/...

@Marico  Ok.

** If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution, so that it comes in top of the search and help others. Thank you !

Good Luck 👍

 

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