Hello @Aura02 , and welcome to the KNIME community.
I’ve deployed an alternative solution for your use. This alternative solution is also supported with ‘Column Expressions’ node; however it deals with the problem with very simple math, using by ranges the full cumulative column for each of the variables scoped in the equation. Then no loop is needed, improving in performance.
As @takbb commented, it wasn’t clear for me either the excel formulas coming from the image… then I decided to simplify the equation as:
Weekly Balance = [A] Initial Stock - [B] Client Orders + [C] Incoming Stock
You can work with the full cumulative column for each variable, and individualize the ranges (this is $Product$) accessing with Column Expressions’ Offset function.
Then the equation becomes:
Weekly Balance = [A] - [B] + [C]
- [A] == column offset $Initial Stock$
- [B] == cumulative $Client Orders$ (delta range)
- [C] == cumulative $Incoming Stock$ (delta range)
For example for the [B] variable $Client Orders$ (delta range) in Row5 (‘Jeans’ product range):
The [B Row5] calculation is 5 + 1 + 2 => 51 + (5 - 48) = 8
In the same way [C Row5] calculation is 40 + (5 - 23) = 22
And the outcoming $Weekly Balance$ [Row5]: 10 - 8 + 22 = 24
The Column Expressions’ code is as follow:
// column offset $Initial Stock$
column("Initial Stock", column("ROWINDEX_offset") - column("ROWINDEX"))
// minus cumulative $Client Orders$ (delta range)
-(
column("Sum(Client Orders)") +
( column("Client Orders", column("ROWINDEX_offset") - column("ROWINDEX"))
- column("Sum(Client Orders)", column("ROWINDEX_offset") - column("ROWINDEX")) )
)
// plus cumulative $Incoming Stock$ (delta range)
+(
column("Sum(Incoming Stock)") +
column("Incoming Stock", column("ROWINDEX_offset") - column("ROWINDEX"))
- column("Sum(Incoming Stock)", column("ROWINDEX_offset") - column("ROWINDEX"))
)
Any comment or clarification request is welcome.
BR