HI @tb_g_23, part of your challenge will be to collect together the various rows that form one activity and to determine which combination of rows when added together form the total amount for the activity.
When you have this information, you would then be better placed to decide which row (or rows) not to include.
While a recursive loop might be a possibility, from experience such calculations, which have to take into account all of the the different combinations of rows for each activity would be quite slow to perform. This is one area where loops in KNIME are generally insufficiently performant, and a small amount of code in either python or java using some standard libraries, if available will be beneficial and ultimately easier to code.
Your challenge has logical similarities to a problem that was posed here two years ago
In this case it was summing columns rather than rows. Of course the only difference between columns and rows is a transposition of a table (or a pivot), so actually I believe this could form the basis for a solution. If you take a look at that post, you will see that various loop options were considered, but the solution I ended up with was a very small python script based in fact on the example provided by the original poster on that thread.
I have been looking at reworking that to assist with your question, and if I have some time over the weekend, I will see if I can make it work. I believe it will.
Do you have python installed? The python itertools module is ideally suited for deriving the combinations and a whole lot easier than trying to “no-code it” in nodes.
To give an idea of where I’m going with this…
take a look at the activity 4456764. Here you have 4 activities of
5149.18
5149.18
19.98
0
But your total activity amount is 5169.16 whereas the total for those 4 rows is 10318.34. Not surprisingly, you have this down as possibly some removes and two idk
However, running it through a modified version of my script (still a work in progress!), it is telling me that the “target” amount of 5169.16 can be formed from the following combinations of those above amounts:
5149.18 + 19.98
or
5149.18 + 19.98 + 0.0
which, with some additional work can probably tell us to simply drop one of the 5149.18 values and keep the other three rows. Which one to drop would be arbitrary (first?, last?). Anyway that’s where I’m heading.