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

Struggling to figure out how to work with parent/child data - how can I filter by parent?

I have a dataset that includes a table called "Spaces". That table includes spaces with "SpaceIDs" and also "ChildrenIDs" as another column for spaces with Children IDs. Children IDs are also SpaceIDs. 

 

I broke it up into two tables and created a "SpaceRelationship" table that maps SpaceIDs to ChildrenIDs. I also added a Path column for the hirarchy. I am trying to figure out what's next and how I can actually use this to say, return all the data from the children IDs of a space. 

 

The data is structured like this example: 

-A SpaceID for a building may have 5 ChildrenIDs representing each five floors, these ChildrenIDs are also SpaceIDs

-Each of the 5 ChildrenIDs representing each floor may have 1-500 or more ChildrenIDs that represent different rooms on the floor

 

My goal is to answer questions like: 

-How many spaces are there in a given building, what are the floors, what are the spaces under each floor

-I have other tables that connect on SpaceID, such as space occupancy, I want to be able to see the occupancy level for a building, and then drill down and see it by floor or roomDataStruct1.pngDataStruct2.png

 

Any ideas for how to set this up and actually make use/sense of the parent/child relationship? 

2 REPLIES 2
v-chenwuz-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please use PATH(<ID_columnName>, <parent_columnName>) to return a path and use PATHLENGTH(<path>) to return the level, the level is a number. For example, a is the parents level and aa is the children1 level and aaa is children2 level which parent is aa. And so on. So, the PATHLENGTH(<path>) will return 3 for aaa.

 

For more details, you can refer this:

Understanding functions for parent-child hierarchies in DAX - DAX | Microsoft Learn

 

Best Regards

Community Support Team _ chenwu zhu

 

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

Anonymous
Not applicable

Once I have the PATHLENGTH column, how do I use it to sort/drill with the data? 

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.