Connecting per rows

Hi,

I need help. I have a data (see below). Just wanted to ask if there is a shortcut to have the output? Thanks!

DATA:
Column 1
10000008
10000237
10000001

Column 2
LIFNR
LIFNR
LIFNR

and the OUTPUT I need is:
(LIFNR ‘10000008’ OR
LIFNR ‘10000237’ OR
LIFNR ‘10000001’)

Hi @AlyKnime

One way of doing this is to concatenate your columns using String Manipulation to get you the LIFNR ‘100nnnnn’ part which is common to all rows, then use Column Expression to “decorate” the rows with the bits which are specific to the first row, last row and other rows, based on the following logic:
Row 1: “(” + commonoutput + " OR"
Middle Rows commonoutput + " OR"
Last Row: commonoutput + “)”

See attached workflow.
KNIME_connecting_per_row.knwf (11.4 KB)

You could of course do the entire concatenation in Column Expressions and get rid of the String Manipulation altogether. It’s personal preference but I prefer to keep the “common” processing and the dynamic processing separated, and it also serves as a demo of different nodes. However, if you had a huge data set and performance were an issue, then bringing them into the one single node would probably be more efficient.

(edit - this is a related side message to @TotalDataLoss - this is my “future self” who, as I predicted, hasn’t wasted any time today because of the rowIndex bug you pointed out 6 days ago! :wink:
RowIndex calculated wrongly? - #9 by takbb)

5 Likes

Have modified it but too late to edit my previous post. This workflow also handles the unstated edge case of what happens when there is only a single row of data, so I modified the logic in the Column Expression…

if (rowCount()==1)
{
// edit: special case if we only have the one row
join("(",column(“Output”),")")
}
else
{
… do the previous code
}

KNIME_connecting_per_row-2.knwf (18.3 KB)

4 Likes

Love the modified version @takbb , since it’s bullet proofing the workflow :slight_smile:

2 Likes

Thank you again for your help!

2 Likes

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