Forum Discussion

StevenT's avatar
StevenT
Helper V
1 year ago
Solved

Creating a dynamic slicer

 

Hi, I created a field parameter and on the left side are the 6 fields that I've set up.  On my right side is a filter ("Choose Track(s)").

I want that when the user clicks on each button, the description changes to "Choose Album(s)", "Choose Artist", etc.

I can create a measure that does that but I can't seem to create a way that changes the slicer to use the field as specified, when the user clicks a button 

I used a switch dax measure but that didn't help.  Here's my code

_Switch Slicer DD =
Switch(
        TRUE(),
        '_Switch 6 Metrics'[_Switch Slicer Sel]=1,('_Switch 6 Metrics'[_Switch Slicer Fields]),
        '_Switch 6 Metrics'[_Switch Slicer Sel]=2,Album[Album],
        '_Switch 6 Metrics'[_Switch Slicer Sel]=3,Artist[Artist],
        '_Switch 6 Metrics'[_Switch Slicer Sel]=4,Genre[Genres],
        '_Switch 6 Metrics'[_Switch Slicer Sel]=5,RecordLabel[Recordlabel],
        '_Switch 6 Metrics'[_Switch Slicer Sel]=6,PurchasedFrom[PurchasedFrom]
     )

The error I'm getting is that the fields that are in bold, are not recognized, unelss I aggregate them, which would not make sense in a slicer.

Any ideas on how to resolve this? My goal is to have one slicer on the page no matter which metric the user clicks on.

Thanks, Steven Taub


  • Hi StevenT 

     

    If you're meaning to change the slicer header, you can conditionally format it using a measure that responds to the selected value of the Parameter Order column.

     

    Slicer Title = 
    SWITCH ( SELECTEDVALUE ( Parameter[Parameter Order] ), 0, "Text", 1, "Text2" )
    

     

     

     

  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi StevenT ,

     

    Do you want to select column names in Slicer1 and show values of selected column in Slicer2?

    If so, please refer to the method in message 3, that may be what you want.

     

     

     

     

     

    Best regards,

    Mengmeng Li

8 Replies

  • Hi StevenT 

     

    If you're meaning to change the slicer header, you can conditionally format it using a measure that responds to the selected value of the Parameter Order column.

     

    Slicer Title = 
    SWITCH ( SELECTEDVALUE ( Parameter[Parameter Order] ), 0, "Text", 1, "Text2" )
    

     

     

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi StevenT ,

     

    I'm afraid you'll need to create a custom table for dynamic slicer, because in Power BI, slicers are typically used to filter data, and they're mostly used with column fields, not measures. The measure is the result of a dynamic calculation and cannot be used directly as a field in the slicer.

     

    1. Use Union to combine all the columns in the parameter and their corresponding order into a new table.

    Table 2 = DISTINCT(UNION(ADDCOLUMNS(SELECTCOLUMNS('Album',"Field",'Album'[Album]),"Order",0),ADDCOLUMNS(SELECTCOLUMNS('Artist',"Field",'Artist'[Artist]),"Order",1)))
    //Add other fields as Album and Artist.

    2. Add "one to many" relationship between parameter and custom table.

    3. Use "Field" column in dynamic slicer. Then the slicer will show selected column values when you select parameter slicer.

    4. If you want dynamic slicer to filter origianl tables, you can create relationships between them.

    5. For the changed title of dynamic slicer.

    Measure = SWITCH(SELECTEDVALUE(Parameter[Parameter Order]),0,"Choose Album",1,"Choose Artist")

     

    Here is my test and attached pbix file for your reference. I am showing value of Table[Date] and Table(2)[Test1] in dynamic slicer.

     

     

     

     

    Best regards,

    Mengmeng Li

  • Thanks for this.  I have been able to change the title with no difficulty, it's what I want to do with the data source, that I've run into a challenge.  
    Any ideas about the data source?