Conditional incrementing for a dynamic label?

ABQ_NR_DLY_LOG_v1.xlsx (25.1 KB)

So I am trying to setup a dynamic label for a repeat. The goal is to have certain pieces of information visible from the "table of contents" screen in ODK Collect, that way the user can refer to their progress while recording at a glance instead of having to actually open any particular instance of a repeat.

The catch I have run into involves adding an increment to the label for only certain repeats. For some recordings, it is not necessary to track how many have been counted, but for others it is necessary to know if the current recording is the first, second, third, and so on and so forth.

The calculation I've come up with uses the sum() function to conditionally count the relevant repeats and then display them in the label. But because ODK recalculates each time a group/repeat is open, the label for each entry is always the total number of relevant repeats, not a sequential list of which was the first, second, third entry.

I am a bit stumped as to what to try next. I can't use once() because I need the calculation to run once for each repeat, not once per instance. I can't use position() because there may be a circumstance where the relevant repeats are non-sequential, e.g. relevant, irrelevant, relevant, in which case the labels would display as relevant 1, relevant 3.

Is there any way to store the result of a calculation so it is preserved for an individual repeat? Or can someone think of some elaborate comparison I could do to make this work?

I've attached my form in case the above doesn't make any sense.

All right, well since I didn't hear anything from anyone, I tried a different approach. Basically I wrote some recursive calculations that would check the sum calculated during the previous repeat and then increment if needed.

The code is as follows:

Calc1: number(if(../../r1/g4/drainage = 'yes', 1, 0))
Calc2: if((position() = 1 or position() = 0), indexed-repeat(${r1}, ${calc1}, position()), (indexed-repeat(${r1},${calc2}, (position() - 1)) + indexed-repeat(${r1}, ${calc1}, position())))

When I upload the xlsx I get a dependency cycle error, which I would understand if it weren't for the fact that the conditionals I wrote provide an eventuality for when there is no data. Any thoughts?

ABQ_NR_DLY_LOG_v1a.xlsx (25.1 KB)