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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Siboska
Helper II
Helper II

Build a level column showing the depth based on a child parent relationsship

Hi, 

I need to create a calculated dax column to show what depth in a child parent relationsship the current row is on within each group. 

ItemIDParentIDGroupIDOUTLINE LEVEL
10NULL11
111012
121113
131214
141012
515322
525322
53NULL21
545223
555223
565424
15715835
15815934
15916033
16016232
16116232
162NULL31

Siboska_0-1675869907038.png

 


As shown in the data table I have a ItemID column a Parent Id column and a Group column. 
From this I need to create an Outline Level column to show what level in the hirachy the item is. Null will always be the highest hirachy corresponding to 1 within each group.

6 REPLIES 6
tamerj1
Super User
Super User

Hi @Siboska 
Please try

OUTLINE LEVEL =
PATHLENGTH ( PATH ( 'Table'[ItemID], 'Table'[ParentID] ) )

I need something more flexible. It can happen that a items parent is deleted or been placed outside a group. Therefore I somehow need to incorporate that is must do the PathLength logic within each group and IFERROR then just blank it. 

@Siboska 
You might need splitting by group only if you have ID's that are repeated in different groups. As of the sample data provided that won't be needed. If you have blanks in such data where the ID is not supposed to be blank then you need to fix the data as otherwise you'll obtain wrong hierarchy analysis even if blank out errors.
OUTLINE LEVEL 2 in the following aggregates between different groups yet for this sample data it is providing the same result.

2.png1.png

Hi I'm getting the following error using 

Each value in 'Tasks'[ItemId] must have the same value in 'Tasks'[ParentId]. The value 'xxxx' has multiple values.

This is why I need to Isolate the Hirachy within each group because ItemID can be used multiple times across groups.

FreemanZ
Super User
Super User

hi @Siboska 

 

could you explain how Outline Level is defined?

Sure. 

The Outline level is defined by how depth the hirachy inside each group is. 
I have tried to visualize it:

Siboska_0-1675874373760.png


Each house represent a group. So imagin I can have 10 different house (groups) and then the hirachy needs to be build from that top node. 
Rooms, items and so on can be used in the same houses so therefor I need to incoporate the group aspect.

Have tried something similar to this:

 

 

Outline Level := VAR CurrentItem = ItemId VAR CurrentGroup = Group VAR ParentItem = ParentTaskID VAR LevelCounter = 1 RETURN IF ( ISBLANK ( ParentTask ), LevelCounter, CALCULATE ( LEVEL ( 'TableName'[ItemId ], 'TableName'[ParentTaskID], 'TableName'[Group] ), 'TableName'[ItemId ] = ParentTask, 'TableName'[Group ] = CurrentGroup ) & "." & LevelCounter )

 

 

I somehow managed to find the parents parent and so on, comma seperated but my dax skills ends here.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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