Running sum
Source |
|
|
|
|
Result |
|
|
|
|
Part Number |
Qtr |
Qty |
Price |
|
Part Number |
Qtr |
Qty |
Price |
Running Sum |
ABC123 |
QTR 1 |
100 |
3 |
|
ABC123 |
QTR 1 |
100 |
3 |
3 |
ABC123 |
QTR 2 |
150 |
3 |
|
ABC123 |
QTR 2 |
150 |
3 |
6 |
ABC123 |
QTR 3 |
200 |
1 |
|
ABC123 |
QTR 3 |
200 |
1 |
7 |
ABC123 |
QTR 4 |
250 |
3 |
|
ABC123 |
QTR 4 |
250 |
3 |
10 |
ABC124 |
QTR 1 |
200 |
2 |
|
ABC124 |
QTR 1 |
200 |
2 |
12 |
ABC124 |
QTR 2 |
200 |
1 |
|
ABC124 |
QTR 2 |
200 |
1 |
13 |
ABC124 |
QTR 3 |
200 |
1 |
|
ABC124 |
QTR 3 |
200 |
1 |
14 |
ABC124 |
QTR 4 |
200 |
5 |
|
ABC124 |
QTR 4 |
200 |
5 |
19 |
ABC125 |
QTR 1 |
150 |
3 |
|
ABC125 |
QTR 1 |
150 |
3 |
22 |
ABC125 |
QTR 2 |
150 |
3 |
|
ABC125 |
QTR 2 |
150 |
3 |
25 |
ABC125 |
QTR 3 |
100 |
3 |
|
ABC125 |
QTR 3 |
100 |
3 |
28 |
ABC125 |
QTR 4 |
100 |
3 |
|
ABC125 |
QTR 4 |
100 |
3 |
31 |
Code:
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
Bookmarks