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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

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-numbers-in-the-column
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
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.