Let’s says I have this column
I want to duplicate these 3 rows base on the range of the week, for example with 23-24. These two numbers are defined as variable (min and max)
How do I achieve this
Try with this …
KNIME_forum.knwf (24.1 KB)
Could be a use case for the cross joiner node
I have borrowed (stolen) @gonhaddock 's workflow and put two alternatives. I also adjusted the MIN and MAX values to be 23,30 to make it a little clearer what all the additional nodes are for prior to the cross-join (i.e. generate rows for 23,24,25,26,27,28,29,30)
In this workflow, the second example is “low-code” rather than “no code” as it uses a java snippet, but it is a simple piece of code that makes use of a feature of java snippets whereby they can “remember” the value of a variable calculated for the previous row, and so can be used to derive the incrementing week number… The “no code” version is to use a node such as “Rank” or “Counter Generation” to provide a counter that gets added to the MIN value for each row, which is effectively @gonhaddock’s approach.
I thought it might be useful to see differing but similar approaches…
Expand weeks and cross join.knwf (30.7 KB)
It’s true that commenting the nodes gains comprehensiveness, indeed. And nice to see different approaches.
The only missed requirement from @NoobZik in your workflow is “These two numbers are defined as variable (min and max)” … I just assumed that passing visually the ‘variables’ to ‘data flow’ in the nodes was part of the question, as the matching of the example provided.
We know snippets can handle variables environment, and increasing in code functionality can ends up in a unique Snippet (Java, R, Py)
hi @gonhaddock ,
To use actual variables from flow variables, instead of “variable values” via a Table Creator, a couple of Integer configs and a Variable to Table Row would act as a suitable replacement for the Table Creator, and use of a java snippet in place of Rank and Math Formula is not a particularly material change to the flow…
I forgot to put my first attempt to approach this workflow, it worked from 1 to x after a Rule-based Row Filter (removing the 0) due to starting from 0 (ticking Add Iteration column into the Loop End node)
@gonhaddock The following image should clarify how I meant “These two numbers are defined as variable (min and max)”
And as a final note, thank you for the differents approaches to tackle this, I will report back once I tested it myself
Hi @NoobZik , I think any of the flows provided will achieve what you need as they effectively do the same thing using small variations so it’s just a case of finding the one that works best for you and slotting it in at the right point in your flow, and yes putting it in a loop works too… I’d try to avoid loops where possible on very large datasets as they can be slower, but for stuff like this, sometimes it can simplify things
The fun thing with KNIME is that there are often so many ways to achieve the same end…
The challenging thing (sometimes) is finding even just ONE of those ways!
Thank you everyone, I adapted @takbb workflow to my needs in order to get less node edits
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.