Connect different families with duplicate IDs

Hello my friends, I need some help.

I need to update some detail item element parameters linked with fabric sheet. My problem is that I have duplicate IDs for the fabric sheets and this routine that I have only updates one Detail Item with the same ID, I need to update both.

Please, can anyone help me