Call same workflow from different nodes with different tables

Hi. I am very new to Knime.

I have a base table and want to summarise it at different levels (group by) of detail. Each time I do that, I need to calculate a percentage, using if(COL_A = 0,0,COL_B/COL_A).

Rather than having to put a Maths node after every GroupBy node, is there a way to have a Metanode or callable workflow which will take the table output from the calling node and return it, at the correct level of detail?

I can’t see how to achieve this with containers or metanodes, and not sure which area of functionality to read up on. I’d appreciate any tips.

Hi,
I don’t completely understand your use case. First you group by a couple of columns, then COL_A and COL_B are in the result but how are they aggregated? Or are they part of the group columns? Generally, you can probably wrap your logic into a component and use a Column Selection Configuration node to add a column selection to the component’s configuration dialog. Then you can select your group columns there and pass them via flow variable to the GroupBy node, followed by a Math Formula, which is the output of the component.
Kind regards,
Alexander

Thanks for your reply. To clarify:

  1. I group by columns. COL_A and COL_B are aggregated using SUM.
  2. Then I have a Math formula to do if(COL_A<0,0,COL_B/COL_A).

This is straightforward. My use case is that I have the same detail table with 5 GroupBy nodes coming off in parallel, because I am grouping by different sets of fields. However in each case, I aggregate COL_A and COL_B, and then have to have a following Math Node with exactly the same formula. Not exactly DRY. My objective is that if I have to have 5 GroupBy nodes, then ideally I would just want to have a single called Node / Workflow that can be called with parameters, and will pass the result back to the calling GroupBy node. I’m not sure if that’s achievable with Knime.

If I was doing this in Python I would just write a function and pass the table to it. But I don’t know how to do that using Knime nodes (and I don’t want to have to learn how to use Python in Knime at this stage).

Hopefully this is clearer now.

Hi,
I have created an example for you. It is a workflow with a component that contains a more complicated workflow. That component can be configured like any other node and returns the table you require. You can just copy it and change the group columns, making it similar to a function. The difference is that it is not really “called”, but copied into the correct place, but this is generally how KNIME workflows are built.
Kind regards,
Alexander

GroupBy Component.knwf (15.1 KB)

1 Like

Hi
Thanks very much for this! I was missing the fundamental concept of a Component. This should allow me to solve my problem.
Kind regards
Michael

2 Likes

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