Forum Discussion

k_rahul_g's avatar
k_rahul_g
Frequent Visitor
1 year ago
Solved

Adding a summary column for parent at multlevel Hierarchy

Hi, I have a power BI table  (BaseData) with columns as 

WorkItemID, WorkItem Type,  ParentID, Path (created using Path Function) , Effort Esitmate, Effort Spent. 

 

for Simplicity, I have added another table (Parent_Child) that has just 2 columns - Parent ID and Child ID ( both referrring to workitems in parent table)

 

I want to add a column at workitem level, that goes recursively in the hierarchy and adds effort values for all child workitems. 

 

I know it can be done using "PathContains" function, but due to large size of the dataset, powerBI just hangs before the calculation is completed. 

 

sample Data 

workItemIDParentIDworkItemTypeTask CategoryPathCategory_Path_Total Estimate_Total Effort
10208532963Task 3465|32963|102085Program Epic | Story | Task |  |  |  |  |  | 1616
10208732963Task 3465|32963|102087Program Epic | Story | Task |  |  |  |  |  | 3232
10233732963Task 3465|32963|102337Program Epic | Story | Task |  |  |  |  |  | 3232
10234032963Task 3465|32963|102340Program Epic | Story | Task |  |  |  |  |  | 88
10285932963Task 3465|32963|102859Program Epic | Story | Task |  |  |  |  |  | 88
10286632963Task 3465|32963|102866Program Epic | Story | Task |  |  |  |  |  | 2424
10286732963Task 3465|32963|102867Program Epic | Story | Task |  |  |  |  |  | 1616
10286832963Task 3465|32963|102868Program Epic | Story | Task |  |  |  |  |  | 2424
10287032963Task 3465|32963|102870Program Epic | Story | Task |  |  |  |  |  | 2424
10400932963Task 3465|32963|104009Program Epic | Story | Task |  |  |  |  |  | 16
10401032963Task 3465|32963|104010Program Epic | Story | Task |  |  |  |  |  | 1616
10401532963Task 3465|32963|104015Program Epic | Story | Task |  |  |  |  |  | 2424
10401632963Task 3465|32963|104016Program Epic | Story | Task |  |  |  |  |  | 2424
10401832963Task 3465|32963|104018Program Epic | Story | Task |  |  |  |  |  | 3232
10582532963Task 3465|32963|105825Program Epic | Story | Task |  |  |  |  |  | 2424
10582632963Task 3465|32963|105826Program Epic | Story | Task |  |  |  |  |  | 3232
10582832963Task 3465|32963|105828Program Epic | Story | Task |  |  |  |  |  | 2424
10582932963Task 3465|32963|105829Program Epic | Story | Task |  |  |  |  |  | 2424
10710732963Task 3465|32963|107107Program Epic | Story | Task |  |  |  |  |  | 2424
11174132963Task 3465|32963|111741Program Epic | Story | Task |  |  |  |  |  | 2424

 

  • Hi k_rahul_g - Ensure that your BaseData table and the Parent_Child table have the necessary relationship based on the WorkItemID and ParentID. This will help DAX understand the hierarchy.
    Recursive Summation Using a Measure the Effort Esitmate across all child work items:

     

    Total Effort Recursive =
    VAR CurrentWorkItem = MAX(BaseData[WorkItemID])
    VAR ChildEfforts =
    CALCULATE (
    SUMX (
    FILTER (
    BaseData,
    BaseData[ParentID] = CurrentWorkItem
    ),
    [Effort Estimate]
    )
    )
    VAR RecursiveChildEfforts =
    CALCULATE (
    SUMX (
    FILTER (
    Parent_Child,
    Parent_Child[Parent ID] = CurrentWorkItem
    ),
    [Total Effort Recursive]
    )
    )
    RETURN [Effort Estimate] + ChildEfforts + RecursiveChildEfforts

1 Reply

  • Hi k_rahul_g - Ensure that your BaseData table and the Parent_Child table have the necessary relationship based on the WorkItemID and ParentID. This will help DAX understand the hierarchy.
    Recursive Summation Using a Measure the Effort Esitmate across all child work items:

     

    Total Effort Recursive =
    VAR CurrentWorkItem = MAX(BaseData[WorkItemID])
    VAR ChildEfforts =
    CALCULATE (
    SUMX (
    FILTER (
    BaseData,
    BaseData[ParentID] = CurrentWorkItem
    ),
    [Effort Estimate]
    )
    )
    VAR RecursiveChildEfforts =
    CALCULATE (
    SUMX (
    FILTER (
    Parent_Child,
    Parent_Child[Parent ID] = CurrentWorkItem
    ),
    [Total Effort Recursive]
    )
    )
    RETURN [Effort Estimate] + ChildEfforts + RecursiveChildEfforts