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
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
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.

Top Solution Authors