Search code examples
powerbidaxslicers

Slicer filtering on a list inside a table


assuming I have a table that has a list inside

+---------+--------------+
|   tag   |     val      |
+---------+--------------+
| [a,b,c] | 1            |
| [a,e]   | 2            |
| [f,g]   | 3            |
| [e,f]   | 4            |
+---------+--------------+

can I create a slicer that when selected will still filter the item inside the list of the tag column?

eg. i select on the filter "a" it will show 1 and 2. "e" will filter 2 and 4, "f" will filter 3 etc.


Solution

  • You may create a measure (returning 1/0) where you use PATHCONTAINS function. We need to remove square bracket and replace commas to pipe "|"; This measure you can put to filter pane in table/matrix visualization https://dax.guide/pathcontains/

    ForFilter = 
    var __selectedTag = SELECTEDVALUE(disconnected[tagList])
    var __tags = SELECTEDVALUE('Table'[Tag])
    var __path = SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(__tags,",","|"),"[",""),"]","")
    return
    
    IF(PATHCONTAINS(__path, __selectedTag),1,0)
    

    enter image description here

    EDIT: version for multiple selection

    var __string = CONCATENATEX( VALUES(disconnected[tagList]), disconnected[tagList],"|")
    var __tags = SELECTEDVALUE('Table'[Tag])
    var __path = SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(__tags,",","|"),"[",""),"]","")
    VAR Table0 =
        SELECTCOLUMNS(
        TOPN(1,
        SELECTCOLUMNS(
        ADDCOLUMNS (
            GENERATE (
                ROW ( "tag", __path ,"Text",__string ),
                VAR TokenCount =
                    PATHLENGTH ([Text] )
                RETURN
                    GENERATESERIES ( 1, TokenCount )
            ),
            "Word", PATHITEM ([Text], [Value] )
            
        ),
        "Word",IF(PATHCONTAINS([tag],[Word]),1,0),
        "Tag", [tag],
        "Values", [Value]
        ), [Word],DESC, [Values])
        ,"Bool", [Word])
        return
    
        Table0
    

    enter image description here