Forum Discussion
Conditional formatting for a text column
Hi PBI community,
Is there a way to change the background or font color of a table cell for a text based column using DAX.
Any help would be appreciated.
Thank you!
21 Replies
- hashahAdvocate II
I have found a solution which may help which I got help from one of my team members:
- Create a number value for the word by creating an additional column. For example 'Yes' as '1' and 'No' as '2'.
- Make sure the additonal column value is a whole number and not text.
- Apply and close
- Go to the field, use the drop down in the fields section and choose 'conditional formatting' - choose Background or Font colour.
- Choose 'Rules' for 'Format by'
- 'Summarization' as 'Minimum'
- Choose the number and the colour If value is '1' then 'Green'
- Click OK and it should work :)
- AnonymousNot applicable
Exactly what I was looking for, thanks. Mind you, being able to apply a format directly to a field based on a text value doesn't seem like it would be that difficult. It's certainly been something that I could do in Excel for years - come on Microsoft.
- AnonymousNot applicable
Perfect, thanks!
- AnonymousNot applicable
This one helped me solve a problem, one that blocked me all day, many thanks! I got as far as you did up to creating a column to be numbers assigned from another column that is Red, Amber, Green until the conditional formatting lost me, but you helped me solve that one.
The business logic was to calculate the number of months between now and a future date, then using business rules to create a RAG upon them.
Red -> Months to Expiry <=12
Amber -> Months to Expiry >12 and <=24
Green -> Months to Expiry >24
Months To Expiry = DATEDIFF(TODAY(),Query1[contract_expiry_date],MONTH)PropRAG = IF(AND(Query1[Months To Expiry]>=0,Query1[Months To Expiry]<=12),"RED",IF(AND(Query1[Months To Expiry]>12,Query1[Months To Expiry]<=24),"AMBER",IF(Query1[Months To Expiry]>24,"GREEN")))PropRAG2 = IF(Query1[PropRAG] == "RED",1,IF(Query1[PropRAG] == "AMBER",2,IF(Query1[PropRAG] == "GREEN",3)))Then used conditional formatting as you outlined within your solution to assign the colours based on the values from PropRAG2 🙂Thanks again!
- albertopFrequent Visitor
I had the same problem and this is what I did:
- Create a new column
- Create an IF formula based on your text column, make it take numbers instead of the values. For example, my text column contained "Yes" and "No". I used the formula New column = IF([Textcolumn]="Yes",1,0).
- Go to the Conditional formatting option and chose to conditional format based on another column, chose your newly created column.
- You can do this with the first two types of conditional formatting: by color scale and by rules.
- AnonymousNot applicable
why is it if i choose conditional formating based on another column it automaticly uses SUM but i do not want it to sum just take the value
- kevcurtisAdvocate I
As an alternative you can use a measure to retrieve the first value for conditional formatting instead of column aggregation.
First Value = FIRSTNONBLANK('Table'[Column 1],'Table'[Column 1])
Or try changing the default summarizition for the column in the modeling tab. Click the column, Modeling > Default Summarization
- mh2587Super UserYou can use it with switch function and color codes
XYZ Color = SWITCH(TRUE(),X < 0,"#FF0000",Y = 0, "#FFFF00",Z >0, "#00FA9A","#00FA7A" )- AnonymousNot applicable
This method works perfectly in the Sept. 2021 version. Simply create a Calculated Column based on the original column using the method above (Hex color codes). Then do conditional formattting on the original field in a table or matrix and pick "Format by" > "Field value", "Based on field" > Your calculated column.
- LiamWhiteAdvocate I
This post provides one method: https://exceleratorbi.com.au/conditional-formatting-with-a-text-field-in-power-bi/
The DAX is essentially:
Colour Test =VAR Dept = SELECTEDVALUE(Projects[Department])RETURN IF(Dept <> BLANK(), "Green", "Red") - v-huizhn-msftMicrosoft Employee
Hi Anonymous,
Up to date, there is no way to change the background or font color of a table cell for a text. Please review the following feature requests and commont on them.Conditional Formatting for Text
Better Conditional Formatting Tools
Best Regards,
Angelia - d_rohlfsResolver II
If you are looking to use DAX, here is an easy formula to use.
Title =
VAR Name1 = IF(SELECTEDVALUE('TABLE'[COLUMN]) = "TEXT", True, False)
VAR Name2 = IF(SELECTEDVALUE('TABLE'[COLUMN]) = "TEXT", True, False)
VAR Name3 = IF(SELECTEDVALUE('TABLE'[COLUMN]) = "TEXT", True, False)RETURN
SWITCH(
TRUE(),
Name1 , "COLOR",
Name2, "COLOR",
Name3, "COLOR")You would just need to type in the table names and columns. This method would require you to type in all of the cell contents that you want to format, but it works great for smaller distinct value distributions.
- Phil_SeamarkMicrosoft Employee
Hi Anonymous
It doesn't look like sorry. Sounds like a great idea though
- kevcurtisAdvocate I
This idea is currently "Started":
Conditional formatting (cell highligh, font, etc) when comparing multiple fields
I've been needing this functionality for months now.
Thanks
Kevin
- AnonymousNot applicable
Thanks for the update kevcurtis
- geekymichelleNew Member
The May Update includes the ability to condtionally format text fields, as long as you choose a numeric value to format on.
- geekymichelleNew Member
The May Update added this functionality. Now, users can conditionally format text and date fields, as long as you choose a numeric value to format on.