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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Conditional formatting multiple columns by text value

Objective: Change background color using a HEX color code based on cell value for columns PBar_01 to PBar_14.

My current solution involves creating 14 measures for each column then use conditional formatting which seems quite cumbersome.  Is there a better approach maybe using a function?

 

MyHeadHurts_0-1597164759374.png

 

 

1.  Create a new measure for PB01 column

 

PB01_BColour =
VAR PBAR01 = SELECTEDVALUE(Latest_Print_Bar_Config[PB01])
RETURN

SWITCH(TRUE(),
PBAR01 = "C", "#00FFFF",
PBAR01 = "M", "#FF00FF",
PBAR01 = "Y", "#FFFF00",
PBAR01 = "K", "#000000",
PBAR01 = "LC", "#E0FFFF",
PBAR01 = "LM", "#FF80FF",
PBAR01 = "O", "#FFA500",
PBAR01 = "V", "#8A2BE2",
PBAR01 = "G", "#008000",
PBAR01 = "W", "#FFFFFF",
PBAR01 = "-", "#D3D3D3")

 

2.  Set conditional formatting for background colour for PB01:

 
 
 

Untitled.png

3. Repeat steps 1 to 2 thirteen times for PB02>PB14

 

I have also used conditional formatting for the Font colour so that means an additional 14 measures.  Surely there must be a way of creating a function whereby you feed in the Text value and it returns a colour without having to define the Column?

 

 

3 REPLIES 3
V-lianl-msft
Community Support
Community Support

Hi @Anonymous ,

 

There is no good solution right now, you need to create so many measures manually.

 

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

amitchandak
Super User
Super User

@Anonymous , You can create a color measure than return color based on condition and use that with "Field" option in conditional formatting

color =
switch ( true(),
FIRSTNONBLANK(Table[commodity],"NA") ="commodity1" && sum(Table[Value]) >500,"lightgreen",
FIRSTNONBLANK(Table[commodity],"NA") ="commodity2" && sum(Table[Value]) >1000,"lightgreen",
/// Add more conditions
"red"
)

 

https://radacad.com/dax-and-conditional-formatting-better-together-find-the-biggest-and-smallest-num...
https://docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting#color-by-color-values

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

But how can this measure be applied to each column? What is Table[Commodity] and Table[Value]? I need to appy conditional formatting based on the value in the specific cell, for each column.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.