concatenating specific rows together

Hello community,
I am trying to concatenate row together but i am finding some diffuculty. I tried a loop but i am missin somtheting. below is a sample data

id flag message indexing
c1 a ggg 1
c1 hello 1
c1 done 1
c1 b text tetx 2
c1 answer 2
c1 C questionquestion 3
c1 answer 3
c1 b 3
c1 v 3
c1 c 3
c2 a text3 4
c2 text4 4
c2 tex5 4
c2 b tex6 5
c2 tex7 5

i need 1st to give an index as previwed above then i need to concatenate all rows that are under a certain flag. when the flag is not empty, it means a question, and when it is empty it means asnswers for that question. so i need to group the answers together.

if anybody can help i would rreally appreciate

If the goal is to put the answers in separate columns on the same line as the question, then you could always use a row splitter to separate out the rows with an empty Flag, then use the Joiner node to Join them back together by the Index number.

1 Like

Still i will need to concatenate the awnsers to its specific question whis also why i need to index them to performe the join later

I think this can work for you:

  1. Split Qs and As by missing value
  2. Process As through group loop to add an “AnswerNo” column
  3. Pivot the As: Group => Indexing, Pivot => AnswerNo, Aggregate => message (First) => by adding the running AnswerNo it is ensured that we are not missing anything
  4. Join both datasets on indexing column

Here’s the prototype:

concatQA.knwf (84.4 KB)

1 Like

Hi @mh_elhassan , are you also asking how to actually create the index column that you have shown? It’s not clear to me if that’s what you want, and I think the answers above generally assume you already have that indexing column… Is that part of the problem?

If so, the creation of the indexing column can be done by using a Rule Engine followed by a Moving Aggregation node as described in the following post

1 Like

3 first nodes to create index.

From missing value node to Column renamer, how to create row of questions. You can adapt to your needs.

Best regards.

KNIME_Elhassan.knwf (84,4 Ko)

1 Like