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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Apala
New Member

How to calculate parent-child hierarchy duration with DAX?

Hi,

 

I have a table which contains a project task hierarchy. Each task has a duration (days)

 

I would need to calculate the duration of the whole path for each Task.

 

E.g. for Task with Id "S002" the duration would be 7 (0+7), For Task "S003" the duration would be 11 (0+7+4), and so on.. any help would be appreciated with the DAX formula.

 

hierarchy_duration.PNG

 

Edit: 

Dax Formula for Path is

Path = PATH(Tasks[Id];Tasks[Predecessor])

 

Sample data as text.

Id;Duration;Predecessor;Path
S001;0;S001;S001
S002;7;S001;S001|S002
S003;4;S002;S001|S002|S003
S004;14;S003;S001|S002|S003|S004
S005;7;S004;S001|S002|S003|S004|S005
S006;7;S004;S001|S002|S003|S004|S006
S007;14;S005;S001|S002|S003|S004|S005|S007

4 REPLIES 4
Greg_Deckler
Community Champion
Community Champion

Can you post your data as text? Really helps when trying to recreate and test these things. Probably some way to do it using the parent child functions in DAX.

 

https://docs.microsoft.com/en-us/dax/parent-and-child-functions-dax



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thanks @Greg_Deckler , added data to the original post

Cool, try this. PBIX is attached. 

 

Total Duration = 
    VAR __Table =
        ADDCOLUMNS(
            FILTER( 
                {
                    PATHITEM([Path],1),
                    PATHITEM([Path],2),
                    PATHITEM([Path],3),
                    PATHITEM([Path],4),
                    PATHITEM([Path],5),
                    PATHITEM([Path],6),
                    PATHITEM([Path],7),
                    PATHITEM([Path],8),
                    PATHITEM([Path],9),
                    PATHITEM([Path],10)
                },
                [Value] <> ""
            ),
            "__Duration",LOOKUPVALUE('parentchild'[Duration],parentchild[Id],[Value])
        )
RETURN
    SUMX(__Table,[__Duration])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi, thanks for the quick reply.

 

The formula seems to be working fine, but the problem here is that my data was only a sample. At the moment, the maximum depth of the path is 25 but there can be even more tasks in a project. 

 

Of course, I can write the formula so that it supports a fixed deoth (e.g. 50), but if it is possible to do the calculation dynamically it would be better. Any suggestions on this?

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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