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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
PowerrrBrrr
Helper III
Helper III

Easy Conditional Text based on column values

Hi I have below visuals which are card visuals whose background has been formatted based on values. Like if value is 0 then red else green. I would also like to show Active and Inactive text for green and red cards. how can I do it?? I do not have Active or Inactive thing anywhere in my data. It is based on values. 

 

PowerrrBrrr_0-1634733423673.png

 

 

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @PowerrrBrrr ,

Here are the steps you can follow:

1. Create measure.

color =
IF(
    MAX('Table'[Value])=0,"red","green"
)
status =
IF(
    MAX('Table'[Value])=0,"Inactive","Running")

2. Select Format – Conditional formatting – Machines – Background color.

vyangliumsft_0-1635298045062.png

3. Enter the Background color interface.

Format by – Field value

Based on field – [color]

vyangliumsft_1-1635298045066.png

4. Result:

vyangliumsft_2-1635298045070.png

Does this match your expected result?

 

Best Regards,

Liu Yang

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

View solution in original post

8 REPLIES 8
v-yangliu-msft
Community Support
Community Support

Hi  @PowerrrBrrr ,

Here are the steps you can follow:

1. Create measure.

color =
IF(
    MAX('Table'[Value])=0,"red","green"
)
status =
IF(
    MAX('Table'[Value])=0,"Inactive","Running")

2. Select Format – Conditional formatting – Machines – Background color.

vyangliumsft_0-1635298045062.png

3. Enter the Background color interface.

Format by – Field value

Based on field – [color]

vyangliumsft_1-1635298045066.png

4. Result:

vyangliumsft_2-1635298045070.png

Does this match your expected result?

 

Best Regards,

Liu Yang

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

Pragati11
Super User
Super User

HI @PowerrrBrrr ,

 

You need to create some measures based on the existing data.

Can you share some sample data here (remove any sensitive information)?

Also share the rules you want for different colors and different values.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Here is the data table. So if you see Machine 3 will be showing Red and should show "Inactive" while all other machine are showing green but should show text "Running" also

MachinesValueTimestamp
Machine1  232021-08-12
Machine2    22021-09-08
Machine3   02021-09-01
Machine1  112021-08-23

Hi @PowerrrBrrr ,

 

Create following measure for giving a background color based on text value:

conditionalColor =
VAR t1 =
    SELECTEDVALUE ( conditionalData[Machines] )
RETURN
    SWITCH ( TRUE (), t1 = "Machine3", "#ff0000", "#009900" )

Then you can use above measure to get dynamic background color for Machines column, something like below:

Pragati11_0-1634734765248.png

Similarly, you can create another measure for Running/Inactive text:

conditionalStatus = 
var t1 = SELECTEDVALUE(conditionalData[Machines])
RETURN
SWITCH(
    TRUE(),
    t1 = "Machine3", "Inactive", "Running"
)

You will something as below:

Pragati11_1-1634734885583.png

 

Let me know how you get along with this solution.

 

Thanks,

Pragati

 

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

But here you are putting Machine 3 as Red and Inactive in your Formulae. In my case it can be any machine.. Machine 3 I gave as an example

HI @PowerrrBrrr ,

 

In that case you need to write a set of rules for me to create a measure. 🙂

You can even modify the above measures based on your requirement.

Also, I don't understand what do you mean by - any machine. Do you want your Machine column value coming from a slicer or how you want it to be?

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

I gave the rule it is when Value is 0. I dont see anywhere in your DAX that you are checking this condition. you are simply selecting the Machine column and for machine 3 you are putting it as RED. We need to have condition to set it as red when value is 0 and that I have already done with conditional formatting. I am now looking to get conditional text based on value

HI @PowerrrBrrr ,

 

I would have liked your description to be consistent when you provided me with the sample data. 🙂

 

Anyways, going with your above description - I am now looking to get conditional text based on value 

 

To get dynamic text based on your Value column, just modify the 2nd DAX that I have shared to use your Value column rather than Machine column.

conditionalStatus = 
var t1 = SELECTEDVALUE(conditionalData[Value])
RETURN
SWITCH(
    TRUE(),
    t1 = 0, "Inactive", "Running"
)

 

Thanks,

Pragati

 

 

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.