Forum Discussion
androo235
Advocate I
3 years agoRunning Total by Category with Compound Interest. List.Accumulate/Generate
Data and XL solution and attempts to solve with Power Query I have been trying to solve this problem with power query. I started by using refer to previous row methods but thought these would li...
ImkeF
Community Champion
3 years agoHi androo235 ,
this function calculates the compound interest:
( RTColumnName as text, MyTable as table, ValueColumn as text, InterestColumn as text) =>
let
Source = MyTable,
BuffValues = Table.Buffer( MyTable ),
RunningTotal =
List.Skip(
List.Generate (
() => [ RT = 0, ValueColumn), RowIndex = 0 ],
each [RowIndex] <= Table.RowCount(BuffValues),
each [ RT = ([RT] + Record.Field(BuffValues{[RowIndex]}, ValueColumn) ) * (1 + Record.Field(BuffValues{[RowIndex]}, InterestColumn)),
RowIndex = [RowIndex] + 1 ],
each [RT]
)
),
#"Combined Table + RT" =
Table.FromColumns(
Table.ToColumns( MyTable )
& { Value.ReplaceType( RunningTotal, type {Int64.Type} ) } ,
Table.ColumnNames( MyTable ) & { RTColumnName } )
in
#"Combined Table + RT"
also check the solution with "fnCompounding" in the file attached.