Forum Discussion
Conditional Formatting Isn't working for two instances
Hello,
I'd like to seek for your help with fixing the conditional formatting I created on a table I visualized.
What I have here are the following:
- a table showing "Amber" as the value under "Growth" column
- The Growth Color which is in hex #FF0000 (Red)
- Growth count which is two
- Basically, the instance of "2" means there's two actual record of growth here
- One is Amber
- One is Green
- Basically, the instance of "2" means there's two actual record of growth here
I created a measure that captures the value of the table (supposedly) and output a hex color to be used for contional formatting:
VAR Classification = SELECTEDVALUE('DataTable1'[Growth])
RETURN IF(Classification = "Green", "#35CE12", IF(Classification = "Amber", "#E1C233", IF(Classification = "Red","#FF0000","#FF0000")))
My Problem:
If there's two instance of growth, it will output the default color which is "Red" but what I want to do here is if I can reference the visualized table's value to the right color displaying.
In this context it should out put "Amber" #E1C233
Sample Data:
Mood_Data
| Logo_ID | Logo | Mood |
| 1 | Logo1 | Red |
| 2 | Logo2 | Red |
| 3 | Logo3 | Amber |
| 4 | Logo4 | Green |
| 5 | Logo5 | Red |
Growth_Data
| Logo_ID | Logo | Growth |
| 1 | Logo1 | Red |
| 2 | Logo2 | Amber |
| 2 | Logo2 | Red |
| 3 | Logo3 | Amber |
| 3 | Logo3 | Green |
| 3 | Logo3 | Red |
| 4 | Logo4 | Green |
| 5 | Logo5 | Red |
Things to do
1. create a matrix, use Logo for rows and user Mood and Growth column for values
2. apply the formula above
Hi, maku_
Try formual as below:
calculated column:
color_flag = SWITCH ( Growth_Data[Growth], "Green", 1, "Amber", 2, "Red", 3 )Classification = VAR min_color = CALCULATE ( MIN ( Growth_Data[color_flag] ), Growth_Data, Growth_Data[Logo_ID] = EARLIER ( Growth_Data[Logo_ID] ) ) RETURN SWITCH ( min_color, 1, "Green", 2, "Amber", 3, "Red" )Conditional formatting measure:
New_Growth_Color = VAR Classification = SELECTEDVALUE ( 'Growth_Data'[Classification] ) RETURN IF ( Classification = "Green", "#35CE12", IF ( Classification = "Amber", "#E1C233", IF ( Classification = "Red", "#FF0000", "#FF0000" ) ) )Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
3 Replies
- amitchandak
Super User
maku_ ,
Try with this small variation. And Try use Switch( True().
Growth_Color =
VAR Classification = Max('DataTable1'[Growth])
RETURN IF(Classification = "Green", "#35CE12", IF(Classification = "Amber", "#E1C233", IF(Classification = "Red","#FF0000","#FF0000")))Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.
- maku_Frequent Visitor
I've uploaded the data table. I can't upload a sample powerbi as the forum doesn't allow it.
Also, for the tweak, you made, it sorta works but not in a dynamic way as it will just pull the last entry
- v-easonf-msft
Community Support
Hi, maku_
Try formual as below:
calculated column:
color_flag = SWITCH ( Growth_Data[Growth], "Green", 1, "Amber", 2, "Red", 3 )Classification = VAR min_color = CALCULATE ( MIN ( Growth_Data[color_flag] ), Growth_Data, Growth_Data[Logo_ID] = EARLIER ( Growth_Data[Logo_ID] ) ) RETURN SWITCH ( min_color, 1, "Green", 2, "Amber", 3, "Red" )Conditional formatting measure:
New_Growth_Color = VAR Classification = SELECTEDVALUE ( 'Growth_Data'[Classification] ) RETURN IF ( Classification = "Green", "#35CE12", IF ( Classification = "Amber", "#E1C233", IF ( Classification = "Red", "#FF0000", "#FF0000" ) ) )Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.