Forum Discussion

PowerrrBrrr's avatar
PowerrrBrrr
Helper III
4 years ago
Solved

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. 

 

 

 

  • Anonymous's avatar
    Anonymous
    4 years ago

    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.

    3. Enter the Background color interface.

    Format by – Field value

    Based on field – [color]

    4. Result:

    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

8 Replies

    • PowerrrBrrr's avatar
      PowerrrBrrr
      Helper III

      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
      • Pragati11's avatar
        Pragati11
        Super User

        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:

        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:

         

        Let me know how you get along with this solution.

         

        Thanks,

        Pragati

         

  • Anonymous's avatar
    Anonymous
    Not applicable

    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.

    3. Enter the Background color interface.

    Format by – Field value

    Based on field – [color]

    4. Result:

    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