First of all thanks a lot for your contributions on this subject. It took me a while to try to understand all the work you did and I am not even sure I do fully understand it as I have no coding back ground.
Anyway I used your input to work out a different solution for two scenarios you solved with Previous Row Logic
Previous Row - Sales of days before
To calculate the cumul of something like sales (first day, second day, third day etc)
I used a “coordinate based” logic whereby I use
- first row is 1.1
- second row (including the first row) is 1.2
- third row (including the first and the second) is 1.3
And so on.
This logic uses Lookup and Slice, whereby the starting point always is “1” The RowIndex is the variable.
Lookup(thisTable,RowIndex,RowIndex).sales.slice(1,thisRow.RowIndex).Sum()
The interest rates part 1
In this scenario I used mainly the Power() function. The RowIndex is used as the year. No need for a Previous Row Logic
Product(Power(1+thisRow.Percentage,thisRow.RowIndex),thisRow.Amount)
The interest rates part 2
This is a variation that is based again on the Power() logic (thanks @Paul_Danyliuk using this formula in your code) and instead of using the RowIndex, we need a first year - I used Min() - and the rest follows.
Product(Power(1+thisRow.Percentage,thisRow.[Delta Year]),thisRow.Deposit)
If you start with a year, is is directly a full year, that explains the + 1
In sum, I guess we need the Previous Row logic once in a while (like in my sales example), but not when we calculate interest, that is an optical illusion
Best, Christiaan