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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
JoeFields
Frequent Visitor

DAX PATH but with key value pair

Is there a way to use PATH but with a key-value-pair? I have a parent-child relationship table that has GUIDs for the keys and the readable name for the values and I want to add a column to display the path/tree to each item from the top level. PATH appears to only work with the key but what if you want the displayed text to be a different column value?

 

Here is an example of a snip from my table:

JoeFields_0-1644619306757.png

I want to add a column for the path so it would look kind of like this:

PATH:

Community Center

Community Center > BASEMENT

Community Center > BASEMENT > ELECTRICAL ROOM_B003

...

My parent-child relationships can have varying depth, possibly beyond 10 levels, so I would rather not build manual logic to inspect and lookup every level if at all possible but without a loop or ForEach option in DAX I am not sure there is a clean way to do this.

2 REPLIES 2
Jos_Woolley
Solution Sage
Solution Sage

Hi,

NewColumn =
VAR ThisPath =
    PATH( 'Table'[id], 'Table'[parent_id] )
RETURN
    CONCATENATEX(
        FILTER( 'Table', PATHCONTAINS( ThisPath, 'Table'[id] ) ),
        'Table'[name],
        " > "
    )

Regards

Wow, that is really cool. Thanks! I didn't think it would be that simple.

One thing I noticed is this doesn't handle cases where the IDs are not necessarily in the table in the order from top to bottom. I found some cases where my data records where ordered differently and thus I had the path names in different orders. Fairly easy work around was to add a column indicating the path length and then use that in the CONCATENATEX OrderBy section like this:

 

Location Tree = 
VAR LocationPath = PATH(locations_nodes[id],locations_nodes[parentID])
VAR LocationTable = 
ADDCOLUMNS(
    FILTER(locations_nodes,PATHCONTAINS(LocationPath,locations_nodes[id]) && locations_nodes[parent_id]<>BLANK()),
    "PathPosition",PATHLENGTH(PATH(locations_nodes[id],locations_nodes[parentID])))
RETURN CONCATENATEX(
    LocationTable,
    locations_nodes[name],
    " > ",
    [PathPosition],ASC
    )

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.