Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Conditional Formatting with IF statement

Hey All   Like the title says I am trying to do conditional formatting with an if statement but based on social media platforms' engagement rate and each individual platform has its own KPI. Exampl...
  • kpost's avatar
    3 years ago

    I'll do the best I can with the info provided...

    BIG PICTURE, this is what you want to do, ASSUMING the social media company is going to be in the visual, and ASSUMING it's going to be something like a table visual....

    Create a measure that returns a value like 0,1,2,3 etc depending on the conditions and the colors you want.  Maybe 0 will be red, 1 will be green, 2 will be orange, 3 will be blue.  Idk, whatever you want.

    Note that this works because the switch statement stops evaluating once it reaches a statement that resolves to TRUE().


    Conditional_Format_color = 
    var engagement = [engagement rate]
    var media_company = SELECTEDVALUE(TABLE[Social_Media_Company])
    RETURN
    SWITCH(
              TRUE(),
              media_company = "Facebook" && engagement < 0.005, 1,
              media_company = "Facebook", 0
              ----continue adding companies and return values here
    )


    Now, once you have done that, format the [Engagement Rate] field in your visual using the field value [Conditional_Format_color].  Just map each number to the corresponding color using the "Rules" you want, and voila.

    //Mediocre Power BI Advice, but it's free//