@MatOk welcome to the KNIME forum. You might want to check your IDs and make sure you always have the right ID. You can either keep the ID in a separate column and use that or if you want to use RowdID you might have to make sure your RowID is the one you want to use.
I hope this example might help.
You can always convert the current RowID to a column and you can convert a column to a RowID.
return $$ROWID$$;
If you want to handle your duplicates and understand about them you can read this article: