Forum Discussion

Daniel_B's avatar
Daniel_B
Helper II
6 years ago
Solved

Change Table Color based on associated slicer selection

Hi All

 

I'm trying to make the colour of a table change based on the associated slicer selection

 

Would I need to create a measure for all of the available selections (in this instance I have 4, positive, negative, mixed and neutral) and a table with free-text which fall under one of those 4 categories

 

For example:

 

Free Text              Sentiment

Blah Blah Blah      Neutral

 

Would I need to create a measure where free-text row = NEUTRAL, add that to the table then set up a conditional format to show if slicer selection = NEUTRAL then table colour = BLUE

 

If that isn't the case, any links/ideas that might guide me on this one


Thanks


Dan_B

 

  • Hi Daniel_B 


    Create a measure similar to below (you'll need to replace the table name with your actual table name):

     

    Sentiment Colour = 
    VAR SelSentiment = SELECTEDVALUE ( 'Table'[Sentiment] )
    VAR Result =
    SWITCH (
        TRUE(),
        SelSentiment = "Positive", "Green",
        SelSentiment = "Negative", "Red",
        SelSentiment = "Neutral", "Gray",
        SelSentiment = "Mixed", "Orange"
    )
    RETURN Result

     

    Then, head to the formatting pane of your table visualisation and expand Conditional Formatting.

    Select the relevant field and enable 'Background color'.

    Click Advanced controls

     

     

    Select format by 'Field value' and then select your newly created measure.

     

     

    You'll then end up with something like this:

     

     

     

     

     

     

    You can find more info here: docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting 

     

    Hope it helps.


    Best regards,

    Martyn

4 Replies

  • Hi Daniel_B 


    Create a measure similar to below (you'll need to replace the table name with your actual table name):

     

    Sentiment Colour = 
    VAR SelSentiment = SELECTEDVALUE ( 'Table'[Sentiment] )
    VAR Result =
    SWITCH (
        TRUE(),
        SelSentiment = "Positive", "Green",
        SelSentiment = "Negative", "Red",
        SelSentiment = "Neutral", "Gray",
        SelSentiment = "Mixed", "Orange"
    )
    RETURN Result

     

    Then, head to the formatting pane of your table visualisation and expand Conditional Formatting.

    Select the relevant field and enable 'Background color'.

    Click Advanced controls

     

     

    Select format by 'Field value' and then select your newly created measure.

     

     

    You'll then end up with something like this:

     

     

     

     

     

     

    You can find more info here: docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting 

     

    Hope it helps.


    Best regards,

    Martyn

    • Daniel_B's avatar
      Daniel_B
      Helper II

      MartynRamsden , thank you so much for that - works perfectly (colours are a bit bolder than I'd like but I can work on that 🙂 )

       

      Very Much appreciated

      • MartynRamsden's avatar
        MartynRamsden
        Solution Sage

        Hi Daniel_B 

         

        No problem!

         

        You can replace the names of the colours in the DAX expression with the hex code of any colour you prefer.
        There's an example of this towards the bottom of the article I linked to.


        Best regards,
        Martyn