# Iterate over the each row and if it meets the requirements write value to another row

Hey people!
I uploaded two pictures, in first one is how my data looks so far inside of the KNIME, and second one is what I need to calculate as next output.
If my column “business partner check” has value “passed” and if the limit entered by user is not bigger then value from column “max. reimbursment amount” (in this case limit is 600), then my column “reimbursed amount” should look like in the picture number 2.
I tried to do it with Java snippet (simple) but I can not manage to get the data in the way I need it, I lost already 2 days in solving this problem…
I am new here so any help is more then welcome!

Hi @denajaha, can you clarify why the last 3 rows in your output don’t all have 524.6 in the “reimbursed amount” column?

1 Like

Hi @elsamuel, thank you for your reply!
Because only the first row is under the limit entered by user (in this case it is 600), and 524+524 is more than 600, so it has to be 0 until the end of the column.

I managed using this Java code to almost get what I want:
double a = 0.0;
if (\$max. reimbursement amount\$ <= \$\${Dreim. limit check input}\$\$){
if(\$business partner check\$.equals(“passed”)) {
a = a + \$max. reimbursement amount\$;
}
}
return a;

And I used these nodes:

It looks like this so far, any ideas how to get 0 in the fields where limit is excited?

Solved it finally with this code
if ((\$max. reimbursement amount\$ <= \$\${Dreim. limit check input}\$\$)){
if(\$business partner check\$.equals(“passed”) && (a <= \$\${Dreim. limit check input}\$\$)) {
a = a + \$max. reimbursement amount\$;
if(a > \$\${Dreim. limit check input}\$\$) {
return 0.0;
}
}
else {
return 0.0;
}
}
return a;

2 Likes

Hi there @denajaha,

welcome to KNIME Community!

Glad you found solution with Java but why are you looping over columns? Are you doing this for multiple columns? If I understood you correctly a more KNIME way (more readable and easier to maintain although with multiple nodes) would be to first calculate cumulative sum for rows with value “passed” (Row Splitter followed by Moving Aggregation on “passed” output) and then simply apply rule with Rule Engine node followed by Concatenate node.

Br,
Ivan