to generate new column with selected row count


I would like to get the output as a repeating count of repeating rows. Consider AC as the input row which repeats itself from AC1 to AC6. I would like to get the output as new column with count for each group as shown in table. Please let me know the procedure. Thanks

AC Output
AC1 1
AC2 1
AC3 1
AC4 1
AC5 1
AC6 1
AC1 2
AC2 2
AC3 2
AC4 2
AC5 2
AC6 2
AC1 3
AC2 3
AC3 3
AC4 3
AC5 3
AC6 3


Hello nakuld,

This is rather complex to do with native nodes, but easy with a java snippet.

Use two fields: one is a counter, the other the last field.
Then per row: Extract the number from the AC column. compare it to the lasts column. If it is larger output the counter. If it is smaller increase the counter and output it. Then store the number in the lastnumber field.


Hi Ferry. Thanks for your reply. Actually I am new to KNIME. And I have never used java snippet before. So the explanation is difficult for me to put into use.

Oh, I just realized that you have a fixed length for each group, that makes it waaaay more simple.

Have a look at the attached workflow. It iterates over your input by chunks of 6 rows. The Loop End concatenates all chunks again, and adds a column with the number of the chunk it was in.

thanks ferry. I have almost got it. one last question. Is there a possibility to begin iteration with 1 instead of 0

Hey nakuld,

Not as far as I know, because in computer science you start counting at 0.

But you can easily fix that by appending a Math Formula node to the loop end and simply add 1 to the iteration column.


Hi Ferry.abt,

Thank you very much!