Duplicating certain rows

Hello,

I have an input table:

Column1 Column2 Column3
aaaaaa 111111111 111111111
bbbbbb 1222222 13333333
ccccccc 1111111111 111111111
I want to duplicate rows in which in column2 and column3 are only ‘1’ and then append column1 in duplicated rows with ‘1’. So the output would be:

Column1 Column2 Column3
aaaaaa 111111111 111111111
aaaaaa1 111111111 111111111
bbbbbb 1222222 13333333
ccccccc 1111111111 111111111
ccccccc1 1111111111 111111111

Is this possible? Which nodes should I use?

Hi @zielinska_km

You could use a Rule Engine to create a new column called, for example, “dup rows” containing a 1 for rows that you don’t need repeating, or 2 for rows matching your condition. (Make sure you have it creating integers rather than strings.)

Then use the “one row to many” node and have it use the “dup rows” column to determine the number of rows to generate. Where it contains 1 it will simply reproduce the original row. Where it contains a 2, it will duplicate the rows as required.

I think that should do it (as far as the duplication goes)

2 Likes

Once you have the rows duplicated, you could use the Duplicate Row Filter node to find the duplicated rows. Set the option to keep duplicate rows. This will generate an additional column containing either ‘unique’, ‘chosen’ or ‘duplicate’.

You could then use a Row Splitter, to filter those set to “duplicate”, and a String Manipulation node to append “1” to Column1 on those rows.

After that, use a Concatenate node to rejoin the two tables back together, and a Column Filter to remove the unwanted additional columns that have been created.

If you need to retain row order, throw in a Counter Generation node prior to the Row Splitter and then sort using that counter after the Concatenate node.

2 Likes

row splitter, duplicate the rows as @takbb suggested with one to many then concatenate back
br

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