PDA

View Full Version : PQ - Running sum



sandy666
05-09-2020, 07:52 PM
Running sum


SourceResult

Part NumberQtrQtyPricePart NumberQtrQtyPriceRunning Sum

ABC123QTR 1
100
3ABC123QTR 1
100
3
3

ABC123QTR 2
150
3ABC123QTR 2
150
3
6

ABC123QTR 3
200
1ABC123QTR 3
200
1
7

ABC123QTR 4
250
3ABC123QTR 4
250
3
10

ABC124QTR 1
200
2ABC124QTR 1
200
2
12

ABC124QTR 2
200
1ABC124QTR 2
200
1
13

ABC124QTR 3
200
1ABC124QTR 3
200
1
14

ABC124QTR 4
200
5ABC124QTR 4
200
5
19

ABC125QTR 1
150
3ABC125QTR 1
150
3
22

ABC125QTR 2
150
3ABC125QTR 2
150
3
25

ABC125QTR 3
100
3ABC125QTR 3
100
3
28

ABC125QTR 4
100
3ABC125QTR 4
100
3
31



let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
TableType = Value.Type(Table.AddColumn(Source, "Running Sum", each null, type number)),
Cumulative = List.Skip(List.Accumulate(Source[Price], {0}, (state, current) => state & {List.Last(state) + current})),
RT = Table.FromColumns(Table.ToColumns(Source)&{Cumulative},TableType)
in
RT