Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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"
Here is the link to the sample dataset: https://www.kaggle.com/datasets/rohitsahoo/sales-forecasting
Solved! Go to 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/...
@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]
)
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:
** 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 👍 |
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 👍 |
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!