Forum Discussion

Sonu88's avatar
Sonu88
Frequent Visitor
1 year ago
Solved

Unable to Apply Grey Color for Inactive Slicer Values Using DAX

Hello experts,

 

I have a table with two columns: Country and City, and I'm using the Country column as a slicer with multi-selection enabled. Based on the selected countries, the corresponding cities are displayed in a table.

By default, the slicer background colors are red for India, blue for the USA, and green for the UK. What I want to achieve is that when I select a specific country in the slicer (for example, India), the background color of the other countries should turn grey, indicating that they are inactive, until I make additional selections.

I am encountering difficulties in applying the grey color to inactive slicer values using DAX, especially since I'm using the new slicer in Power BI.

  • Sonu88 
    If i understand your requirement correctly, this is the solution you are expecting : 

    here is the link to the pbix file for your reference. Slicer button custom colors.pbix

     

    with the new slicer, we can control the colors when they are in selected state or in Default state ( which is when they are not selected)

    i made following updates in the settings : 

     

    for multi colors based on country name,  i created a measure and used it in the settings when "state" is "selected"

     

    CountryColor = 
    SWITCH(TRUE(),
            SELECTEDVALUE(Countries[Countries]) = "India", "Red",
            SELECTEDVALUE(Countries[Countries]) = "United Kingdom", "Green",
            SELECTEDVALUE(Countries[Countries]) = "USA", "Blue")

     

    remember, for specific colors, you can use hex code aswell instead of writing generic color name

     

    do use this measure; Click the "fx" button  under the fill section when State is "Selected"

     

    in the format style, select "field value",  and then select the measure

     

    this gives the desired output



4 Replies

  • Jpss's avatar
    Jpss
    Resolver II

    Sonu88 
    If i understand your requirement correctly, this is the solution you are expecting : 

    here is the link to the pbix file for your reference. Slicer button custom colors.pbix

     

    with the new slicer, we can control the colors when they are in selected state or in Default state ( which is when they are not selected)

    i made following updates in the settings : 

     

    for multi colors based on country name,  i created a measure and used it in the settings when "state" is "selected"

     

    CountryColor = 
    SWITCH(TRUE(),
            SELECTEDVALUE(Countries[Countries]) = "India", "Red",
            SELECTEDVALUE(Countries[Countries]) = "United Kingdom", "Green",
            SELECTEDVALUE(Countries[Countries]) = "USA", "Blue")

     

    remember, for specific colors, you can use hex code aswell instead of writing generic color name

     

    do use this measure; Click the "fx" button  under the fill section when State is "Selected"

     

    in the format style, select "field value",  and then select the measure

     

    this gives the desired output



  • Hi Sonu88 
    In order to create the functionality you're aiming for, there needs to be an indication of what is selected and what is not selected in the slicer. From the engine's perspective, the mere fact that a column is placed in the slicer already implies a filter. Therefore, unlike regular buttons, which do not include filters and simply have the option for generic settings in a 'disabled' state, this functionality is impossible in a slicer.
    There is an idea about a similar issue that you can vote on + suggest your own, here :
    https://ideas.fabric.microsoft.com/ideas/idea/?ideaid=c4205606-9bc9-ee11-92bd-6045bd7b2c59

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

    • Sonu88's avatar
      Sonu88
      Frequent Visitor

      Hi Ritaf1983 ,

       

      The new slicer has button like features where you can set the conditional logic to fill the color based on state but still it is not applying the color.

      the measure is 

      SelectedCountry =
      IF (
          ISFILTERED(Country[Country]),
           
              IF (
                  SELECTEDVALUE('Country'[Country]) IN VALUES('Country'[Country]), 1, 0
              ),
              0
         
      )

       

      • Ritaf1983's avatar
        Ritaf1983
        Super User

        Sonu88 

        Not exactly, you can apply conditional formatting based on the slicer’s value (just like in any other visualization), but you cannot base it on the actual selection itself. You can set each cell to be in the color you want, but it cannot change upon selecting..there is no indication for it... its like all of the selected due to they are on slicer ...the result of your dax is always 1...when it a part of the slicer

        But if the goal is to show a default slicer as grey then the solution of Jpss  will work perfectly