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
Emily_Kim
Frequent Visitor

Add Running Total for each Item

Hello Everyone,

I need to add a column "Total Time" as running total for the "Time" column until the next Item change. I think I can do this with List.Accummulate but I'm not sure how to use this function.

 

Appreciate if someone in this forum can help me. Thank you very much.

 

ItemSTAGETIMETOTAL TIME
CX229A55
CX229B1015
CX229C1530
DA051A77
DA051B815
DA051D318
DA051E624
DA214B99
DA214C1524
DA214G529
DA214H332
3 ACCEPTED SOLUTIONS
AlienSx
Super User
Super User

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], 
    data = List.Buffer(Table.ToRows(Source)), 
    gen = List.Generate(
        () => [i = 0, item = data{0}{0}, total = data{0}{2}],
        (x) => x[i] < List.Count(data), 
        (x) => [i = x[i] + 1, item = data{i}{0}, total = data{i}{2} + x[total] * Number.From(item = x[item])],
        (x) => data{x[i]} & {x[total]}
    ), 
    tbl = Table.FromRows(gen, Table.ColumnNames(Source) & {"TOTAL TIME"})
in
    tbl

View solution in original post

shafiz_p
Super User
Super User

Hi @Emily_Kim  Go to power query and add a index column. See image below:

shafiz_p_0-1726053254207.png

 

Go to home tab and click advance edition and add the below marked line. Using List.Sum and List.FirstN function you can acheive your desired result. See image below:

shafiz_p_1-1726053356083.png

 

You will get your desired output. See image below:

shafiz_p_2-1726053418994.png

Now you can remove index column and change type of running total.

Hope this helps!!

If this solved your problem, please accept it as a solution!!

Best Regards,
Shahariar Hafiz

View solution in original post

Omid_Motamedise
Super User
Super User

Check this one step code:

let
    Source = Excel.CurrentWorkbook(){[Name="Table5"]}[Content],
    X = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(X, "Custom", each List.Sum(Table.SelectRows(X,  (a)=> a[Index]<=[Index] and a[Item]=[Item])[TIME]))
in
    #"Added Custom"
If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

View solution in original post

3 REPLIES 3
Omid_Motamedise
Super User
Super User

Check this one step code:

let
    Source = Excel.CurrentWorkbook(){[Name="Table5"]}[Content],
    X = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(X, "Custom", each List.Sum(Table.SelectRows(X,  (a)=> a[Index]<=[Index] and a[Item]=[Item])[TIME]))
in
    #"Added Custom"
If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h
shafiz_p
Super User
Super User

Hi @Emily_Kim  Go to power query and add a index column. See image below:

shafiz_p_0-1726053254207.png

 

Go to home tab and click advance edition and add the below marked line. Using List.Sum and List.FirstN function you can acheive your desired result. See image below:

shafiz_p_1-1726053356083.png

 

You will get your desired output. See image below:

shafiz_p_2-1726053418994.png

Now you can remove index column and change type of running total.

Hope this helps!!

If this solved your problem, please accept it as a solution!!

Best Regards,
Shahariar Hafiz

AlienSx
Super User
Super User

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], 
    data = List.Buffer(Table.ToRows(Source)), 
    gen = List.Generate(
        () => [i = 0, item = data{0}{0}, total = data{0}{2}],
        (x) => x[i] < List.Count(data), 
        (x) => [i = x[i] + 1, item = data{i}{0}, total = data{i}{2} + x[total] * Number.From(item = x[item])],
        (x) => data{x[i]} & {x[total]}
    ), 
    tbl = Table.FromRows(gen, Table.ColumnNames(Source) & {"TOTAL TIME"})
in
    tbl

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.

Top Solution Authors