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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
8a5c4b91-8100-4
Regular Visitor

Filter on selected leaf node

Hi,

 

I have a table with 2 columns: source and target. Sample:

 

SourceTarget
CompanyPlant A
CompanyPlant B
CompanyPlant C
Plant ABuilding X
Plant ABuilding Y
Plant BBuilding R
Plant BBuilding S

 

I created the column isLeaf to check for leaf nodes (True or False):

IsLeaf = 
    VAR CurrentNode = FullHierarchy[Target]
    RETURN CALCULATE (
        COUNTROWS ( FullHierarchy ),
        ALL ( FullHierarchy ),
        FullHierarchy[Source] = CurrentNode
    ) = 0

Also, the path is calculated using the PATH() function.

Next, I created the disconnected table Leafs containing only the leaf nodes:

Leafs = 
    SELECTCOLUMNS(
        FILTER(FullHierarchy, FullHierarchy[IsLeaf]),
        "LeafNode", FullHierarchy[Target]
    )

This is the result: 2 disconnected tables.

2022-12-02 14 08 13.png

My goal is to have 2 visuals: a slicer based on Leafs and a table based on FullHierarchy. Selecting a leaf shows only the items that are directly or indirectly connected to it (i.e. part of it's path).

2022-12-02 14 19 02.png

The statement to do so would be something like:

PATHCONTAINS(
    LOOKUPVALUE(FullHierarchy[Path],
                FullHierarchy[Target]
                [Selected Node]),
    FullHierarchy[Target])

The statement above would lookup the path for the selected leaf node, and then check if the node in the table was part of it, to decide whether or not to show it.

 

I've tried countless of variations, but have unable to implement this. Any ideas, suggestions, etc would be greatly appreciated! Thank you!

 

Sample pbix file is available here.

 

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

Hi, @8a5c4b91-8100-4 ;

You could create a flag measure.

flag = 
IF(CONTAINSSTRING(
CALCULATE(MAX('FullHierarchy'[P]),FILTER(ALL(FullHierarchy),PATHCONTAINS([P],MAX('Leafs'[LeafNode])))),
MAX('FullHierarchy'[Target])),1)

Then filter it .

vyalanwumsft_0-1670226756936.png

The final result:

vyalanwumsft_1-1670226774616.png

vyalanwumsft_2-1670226805795.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yalanwu-msft
Community Support
Community Support

Hi, @8a5c4b91-8100-4 ;

You could create a flag measure.

flag = 
IF(CONTAINSSTRING(
CALCULATE(MAX('FullHierarchy'[P]),FILTER(ALL(FullHierarchy),PATHCONTAINS([P],MAX('Leafs'[LeafNode])))),
MAX('FullHierarchy'[Target])),1)

Then filter it .

vyalanwumsft_0-1670226756936.png

The final result:

vyalanwumsft_1-1670226774616.png

vyalanwumsft_2-1670226805795.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

Your path is incomplete

 

lbendlin_0-1670113430542.png

After you add the top parent node this is the measure that you can use for your visual filter

lbendlin_1-1670113679035.png

See attached

Helpful resources

Announcements
Fabric Data Days is here Carousel

Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.