Question about conditional sum

Hi! Whats the most simple way to calculate a sum from specific rows? I want to calculate B+C without grouping. B & C types are not always present tin the loop batch, when neither are, the outcome of the calculation should be 0. Regex perhaps, but how?


When you say “B & C types are not always present tin the loop batch” are the rows missing entirely or are the values blank? Do both have to be missing to set outcome to 0 or just one?

@rfeigel , they might be missing entirely.I was previously doing this by seperating the types and doing the calculation with math node, mut noticed that the joiner fails when the other input table is empty.

@rfeigel is is possible to do the calculation in the the math node sum($field$) with filter of type?:thinking:

And yes, both need to be missing :slight_smile:

Hi @Data_consumer , when you said at the beginning that you want to do this without grouping… A “sumif” is really just some form of row filter followed by a GroupBy aggregation.

The GroupBy node (or additionally in KNIME 5.x, the Row Aggregator node) is the way to do this kind of calculation, after filtering the rows, so I’m not sure why you are not wanting to group or am I misunderstanding what you meant?

Could you supply input and expected output for the following cases? I assume A is always present.
B Absent
C Absent
Both B & C absent

I try to explain this better :slight_smile: so what i have, is a set on types which are a,b & c. I need to calculate the sum of a,b & c and b&c. These sums form unique columns. A is always present, b & c not always or they can be multiple multiple times. I can split the types into 2 different branches, but cannot join them again as sometimes the b&c return an empty table and the workflow fails… Im sure this is something really simple, just cant get my head around it :see_no_evil:

Some sample input and expected output data would help make your issue clearer. Your last description is not the same as your first description. Its hard to help if the problem is not stated clearly and consistently.

I’m still not sure I understand what you’re after, but try this. You can connect the different Table Creator nodes to test different inputs.

1 Like

@Hi @rfeigel & @takbb

I took another deep look into the model and found a way to design the workflow so this problem does not occur at all. Thanks for the help anyways, much appreciated :pray:

1 Like

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