Looking for the wright node

Hi Knime Forum,

I just want to aggregate values and append in new columns. But I want to differentiate between positive and negative values. The result should look like this table:
Col A Col B App. Col A (pos.values) App. Col B (negat.values)
-3 4 1 1
-2 -5 0 2
1 1 2 0

The node Column Aggregation uses the count method in the aggregation method only values and doesn’t differentiate between positive and negative values.
What is the easiest way?

Kind regards,

Ol

Hello @Ol_Broenner,

think easiest way would be scripting. Otherwise you will probably end up with some complicated loop solution. You can use Column Expressions node where you’ll write one expression for sum of positive numbers and one expression for sum of negative numbers. Give this one a try for positive sum:

sum= 0;

for (let i = 0; i < numberOfColumns(); i++) {
  if (column(i) > 0){
    sum = sum + column(i)}
}

Br,
Ivan

2 Likes

Hi Ivan,

works pretty well. I did some modifications. But it works in the expression for positive numbers as well as in the expression for negative numbers. Thanks a lot.

Kind regards,
Ol

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.