Forum Discussion

rschaudhr's avatar
rschaudhr
Resolver II
5 years ago
Solved

Default value when no filter selected

I have a case where I have the following data:

 

There is a slicer based on the department. When Finance is selected in the slicer, another visual will display the comments related to finance. However, when no value is selected in the department slicer, the comments visual should show comments from Investment department.

 

Thank you,

 

Rehan 

  • Hi rschaudhr,

     

    You should use a measure similar to the one below:

     

    Comments selection =
    IF (
        ISFILTERED ( CommentsTable[Department] ),
        SELECTEDVALUE ( CommentsTable[Comments] ),
        CALCULATE (
            SELECTEDVALUE ( CommentsTable[Comments] ),
            FILTER (
                ALL ( CommentsTable[Department], CommentsTable[Comments] ),
                CommentsTable[Department] = "Investments"
            )
        )
    )

     

     

  • Hi MFelix ,

     

    Thank you! It works very well. I should have mentioned earlier. This dax code very works well when you just select one department or there is no selection. It does not work when you select multiple selection. Is there a way to do that?

     

    Thank you again for your help.

     

     

7 Replies

  • Hi rschaudhr,

     

    You should use a measure similar to the one below:

     

    Comments selection =
    IF (
        ISFILTERED ( CommentsTable[Department] ),
        SELECTEDVALUE ( CommentsTable[Comments] ),
        CALCULATE (
            SELECTEDVALUE ( CommentsTable[Comments] ),
            FILTER (
                ALL ( CommentsTable[Department], CommentsTable[Comments] ),
                CommentsTable[Department] = "Investments"
            )
        )
    )

     

     

    • rschaudhr's avatar
      rschaudhr
      Resolver II

      Hi MFelix ,

       

      Thank you! It works very well. I should have mentioned earlier. This dax code very works well when you just select one department or there is no selection. It does not work when you select multiple selection. Is there a way to do that?

       

      Thank you again for your help.

       

       

      • MFelix's avatar
        MFelix
        Super User

        Hi rschaudhr ,

         

        What do you want when more than one is selected on the slicer? All of the values or just the first one?

         

        If you want to concatenate all the values then you should use somethig similar to this one:

         

        Comments selection = 
        IF (
            ISFILTERED ( CommentsTable[Department] ),
            CONCATENATEX(ALLSELECTED(CommentsTable[Comments],CommentsTable[Department]), CommentsTable[Comments], "/"),
            CALCULATE (
                SELECTEDVALUE ( CommentsTable[Comments] ),
                FILTER (
                    ALL ( CommentsTable[Department], CommentsTable[Comments] ),
                    CommentsTable[Department] = "Investments"
                )
            )
        )

         

        Be aware that this gives you a text value with all the comments selected also if you have all the values selected on your slicer what works is the last syntax does not return only the Investment.

         

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi rschaudhr ,

     

    You will need to create a independed department table and use it as slicer.

    slicer = DISTINCT('Table'[DEP])

    Then create a measure as below and add it to visual filter.

    Measure = IF(ISFILTERED(slicer[DEP]),IF(SELECTEDVALUE('Table'[DEP]) in VALUES(slicer[DEP]),1,0),IF(SELECTEDVALUE('Table'[DEP])="INV",1,0))

     

    Best Regards,

    Jay

    • rschaudhr's avatar
      rschaudhr
      Resolver II

      Anonymous , Thank you! This work very well.