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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
eugentov
Frequent Visitor

Dynamic Running Total in Parent-Child Hierarchy

Hello,

I have a list of elements [1 through 7] which are hierarchly ordered as shown in the screenshot below (see diagram).

 

Each element has its own cost (column F). Through a Path Function I was able to trace the Parent-Child Relationship using Power Pivot / Power BI. I would like to know how cna I calculate column G (Dynamic Running Total Costs) in Power DAX, and if there is a way to replicate this in Excel. 


You may see on column I shows how column G was calculated.

 

ParentChild.PNG

 

Additionally, it is desired that if data is filtered out (i.e., 5 is taken out) it will reflect on the remaining entries (running cost would decrease).

 

 

1 ACCEPTED SOLUTION

You can use PATHCONTAINS() as a filter for this.

 

Source data Table:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("NYvBDQAgCAN36ZuHAuowhP3XEBAfJHctNcME1S0ZcDLwd30uwZlp99o++fnKLr37HZybnp/AXe9wvw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Sort Number" = _t, Parent = _t, #"Total Cost" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Total Cost", Currency.Type}})
in
    #"Changed Type"

 

Calculated columns:

Path = PATH('Table'[Sort Number],'Table'[Parent])

Cumulative = 
var s= [Sort Number]
return CALCULATE(sum('Table'[Total Cost]),ALL('Table'),PATHCONTAINS('Table'[Path],s))

 

 

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

Wait what, each hierarchy level has their own cost plus the cost of all their lower levels?!?

correct

You can use PATHCONTAINS() as a filter for this.

 

Source data Table:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("NYvBDQAgCAN36ZuHAuowhP3XEBAfJHctNcME1S0ZcDLwd30uwZlp99o++fnKLr37HZybnp/AXe9wvw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Sort Number" = _t, Parent = _t, #"Total Cost" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Total Cost", Currency.Type}})
in
    #"Changed Type"

 

Calculated columns:

Path = PATH('Table'[Sort Number],'Table'[Parent])

Cumulative = 
var s= [Sort Number]
return CALCULATE(sum('Table'[Total Cost]),ALL('Table'),PATHCONTAINS('Table'[Path],s))

 

 

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.