Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Filter on based on selected slicer value

Hi Experts,

 

I have a table for departments and department Hierarchies.

There is a slicer on Deparment name on a report page , i want the results on the  page to be filtered by the selected department and all its sub department .Kindly help.

 

Sample of Department Table and Department Hierarchy Tables given below.

 

Departments Table 
  
Department 1 
Department 1-2 
Department 1-3 
Department 1-4 
Department 2 
Department 2-2 
Department 2-1 
Department 4 
Department 3 
  
  
Department Hierarchy 
  
Parent ChildChild Department
Department 1Department 1-2
Department 1Department 1-3
Department 1Department 1-4
Department 2Department 2-1
Department 2Department 2-2
Department 4 
Department 3 

 



1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

To create a measure as below.

P = 
VAR a =
    SELECTEDVALUE ( department[department], BLANK () )
VAR parend =
    CALCULATE (
        MAX ( 'Department Hierarchy'[Parent] ),
        FILTER ( ALL ( 'Department Hierarchy' ), 'Department Hierarchy'[Child] = a )
    )
VAR par =
    CALCULATETABLE (
        VALUES ( 'Department Hierarchy'[Parent] ),
        ALL ( 'Department Hierarchy' )
    )
VAR child =
    CALCULATETABLE (
        VALUES ( 'Department Hierarchy'[Child] ),
        ALL ( 'Department Hierarchy' )
    )
RETURN
    IF (
        NOT ( ISFILTERED ( department[department] ) ),
        BLANK (),
        IF (
            a IN par
                && MAX ( 'Department Hierarchy'[Parent] ) = a,
            1,
            IF (
                a IN child
                    && MAX ( 'Department Hierarchy'[Parent] ) = parend,
                1,
                BLANK ()
            )
        )
    )

1.png

BTW, Pbix as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

2 REPLIES 2
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

To create a measure as below.

P = 
VAR a =
    SELECTEDVALUE ( department[department], BLANK () )
VAR parend =
    CALCULATE (
        MAX ( 'Department Hierarchy'[Parent] ),
        FILTER ( ALL ( 'Department Hierarchy' ), 'Department Hierarchy'[Child] = a )
    )
VAR par =
    CALCULATETABLE (
        VALUES ( 'Department Hierarchy'[Parent] ),
        ALL ( 'Department Hierarchy' )
    )
VAR child =
    CALCULATETABLE (
        VALUES ( 'Department Hierarchy'[Child] ),
        ALL ( 'Department Hierarchy' )
    )
RETURN
    IF (
        NOT ( ISFILTERED ( department[department] ) ),
        BLANK (),
        IF (
            a IN par
                && MAX ( 'Department Hierarchy'[Parent] ) = a,
            1,
            IF (
                a IN child
                    && MAX ( 'Department Hierarchy'[Parent] ) = parend,
                1,
                BLANK ()
            )
        )
    )

1.png

BTW, Pbix as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Anonymous
Not applicable

Thanks for the quick turn around, it really helped.

 

As my requirements evolved , i had made a few modifications and craeted a Parent Department Column using logic you provided.

 

Parent Department Layer 2 =

VAR DEPT = Datacube[Department Code 1]
VAR DEPT1 = IF(Datacube[Department Layer]=3,CALCULATE (FIRSTNONBLANK (Departments[Department Code 2], 1 ),FILTER ( ALL ( Departments), Departments[Department Code 3]= FIRSTNONBLANK(Datacube[Department Code 1],1) )),"")
VAR DEPT2= IF(Datacube[Department Layer]=2,DEPT,DEPT1)

Return DEPT2

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.