Forum Discussion

tchamberlain99's avatar
tchamberlain99
Regular Visitor
8 years ago
Solved

Dynamically choose columns based on slicer

I have a table with 4 values :  City Name, State Code,  Data1, Data2.   I am using a Clustered Column chart to Visualize this data. I added a slicer that Selects off the City Name.   If I choose a c...
  • Anonymous's avatar
    Anonymous
    8 years ago

    HI tchamberlain99,

     

    Normal slicer not support operation what you mentioned, you need a few complex steps to achieve similar effect.

     

    First, you need to create new table with city and its percents as source of slicer.

    Selector =
    DISTINCT (
        SELECTCOLUMNS ( table, "City Name", [City Name], "State Code", [State Code] )
    )

    Second, write a measure to get selected item's parent and use it as condition to compare with original table row content to return filter tag.

    In Range =
    VAR _list =
        CALCULATETABLE ( VALUES ( Selector[State Code] ), ALLSELECTED ( Selector ) )
    VAR _current =
        SELECTEDVALUE ( table[State Code] )
    RETURN
        IF ( _current IN _list, "Y", "N" )
    

     

    Finally, apply filter tag on visual level filter to remove unrelated records.(drag to visual level filter and keep item "Y")

     

    Regards,

    Xiaoxin Sheng