Forum Discussion

gab2020's avatar
gab2020
Microsoft Employee
6 years ago
Solved

Multiple Slicers from Multiple Columns

Hi,   I have a table built as following in Power BI.   How to create 2 slicers to filter the table as follows: IdentityNo. Slicer: A slicer with values from IdentityNo. 1, IdentityNo. 2 an...
  • v-alq-msft's avatar
    6 years ago

    Hi, gab2020 

     

    Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end. 

    Table:

     

    Slicer No(a calculated table):

    Slicer No = 
    FILTER(
        DISTINCT(
            UNION(
                DISTINCT('Table'[IdentityNo.1]),
                DISTINCT('Table'[IdentityNo.2]),
                DISTINCT('Table'[IdentityNo.3])
            )
        ),
        [IdentityNo.1]<>BLANK()
    )

     

    Slicer Country:

    Slicer Country = 
    FILTER(
        DISTINCT(
            UNION(
                DISTINCT('Table'[IdentityCountry 1]),
                DISTINCT('Table'[IdentityCountry 2]),
                DISTINCT('Table'[IdentityCountry 3])
            )
        ),
        [IdentityCountry 1]<>BLANK()
    )

     

    You may create two measures as below.

    Visual Control = 
    IF(
        AND(
            SELECTEDVALUE('Table'[IdentityNo.1]) in DISTINCT('Slicer No'[IdentityNo])||
            SELECTEDVALUE('Table'[IdentityNo.2]) in DISTINCT('Slicer No'[IdentityNo])||
            SELECTEDVALUE('Table'[IdentityNo.3]) in DISTINCT('Slicer No'[IdentityNo]),
            SELECTEDVALUE('Table'[IdentityCountry 1]) in DISTINCT('Slicer Country'[IdentityCountry])||
            SELECTEDVALUE('Table'[IdentityCountry 2]) in DISTINCT('Slicer Country'[IdentityCountry])||
            SELECTEDVALUE('Table'[IdentityCountry 3]) in DISTINCT('Slicer Country'[IdentityCountry])
        ),
        1,0
    )
    
    Count UK = 
    var tab = 
    ADDCOLUMNS(
        'Table',
        "flag",
        IF(
            AND(
                'Table'[IdentityNo.1] in DISTINCT('Slicer No'[IdentityNo])||
                'Table'[IdentityNo.2] in DISTINCT('Slicer No'[IdentityNo])||
                'Table'[IdentityNo.3] in DISTINCT('Slicer No'[IdentityNo]),
                'Table'[IdentityCountry 1] in DISTINCT('Slicer Country'[IdentityCountry])||
                'Table'[IdentityCountry 2] in DISTINCT('Slicer Country'[IdentityCountry])||
                'Table'[IdentityCountry 3] in DISTINCT('Slicer Country'[IdentityCountry])
            ),
            1,0
        )
    )
    return
    COUNTROWS(
        FILTER(
            tab,
            [flag]=1&&
            [IdentityCountry 1]="UK"
        )
    )+
    COUNTROWS(
        FILTER(
            tab,
            [flag]=1&&
            [IdentityCountry 2]="UK"
        )
    )+
    COUNTROWS(
        FILTER(
            tab,
            [flag]=1&&
            [IdentityCountry 3]="UK"
        )
    )

     

    Finally you may put 'Visual Control' measure in the visual level filter and use 'IdentityNo', 'IdentityCountry' from 'Slicer No', 'Slicer Country' to filter the result.

     

    Best Regards

    Allan

     

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