Generating sequential numbers in a repeat

1. What is the issue? Please be detailed.
I am trying to implement a simple sequential ID in a repeat. This can be simply done using the position(..) function however the issue is when a user needs to delete a repeat.

2. What steps can we take to reproduce this issue?
For example:
Generally the id will correspond to the position

1 - ID1
2 - ID2
3 - ID3
4 - ID4

If the user deletes ID2 for example, a repeat record however we get:

1 - ID1
2 - ID3
3 - ID4

The ID for the next repeat record added will be based on position 4 again so we will have two duplicate IDs

1 - ID1
2 - ID3
3 - ID4
4 - ID4

3. What have you tried to fix the issue?
I have tried multiple workarounds with varying success. I can get to a solution where the ID generally increments correctly after deleting one or more repeats however each solution generally has a flaw that will result in the counter getting out of whack if the user deletes multiple repeats.

Does anyone have a solution for generating sequential numbers in a repeat?

Welcome @Fyrday,
Would you mind to share the workaround you found so far (as XLSForm extract or screenshot), please. Esp. your formula for the ID.

Would increasing ID with gaps also be ok?

Here is a simple example for sequential numbering inside a loop, without gaps and starting with 1.
Increment04.xlsx (9.7 KB). The following numbers will update if you delete previous cases. You can also reference/show this number for example in a group label (even if the number calculation is inside this group).

Hint: Be careful, if you reference the loop cases later through position as used references can mix up when you go back and delete a case. Example: Household roster and then individual questions referencing name and age of the members.