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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Marico
Helper II
Helper II

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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