Automatically increment an indexer in a repeated group

Greetings,

I have a question regarding the begin_repeat type. As shown in the screenshots below, I want to collect data about students in multiple classrooms. In my form, the respondent is asked to input how many students there is in the classroom (t2_teste). My objective is that: if it’s stated that there are 10 students:

  1. The form will not allow more than 10 repeats.
  2. There will be a counter in each repeat (t2_numero_eleve). The counter starts at 1 and means it’s student 1. Then, when the respondent adds a new repeat, the counter will automatically show 2. This is to help them spot which student they are on in case there is a lot of students to report (example: 50).
    The screenshots below show what I tried so far, but I couldn’t manage to make anything work yet. I realised that last-saved works between forms and is not used for a repeat group. So how should I proceed?

Thanks for any input.


Hi @kevin_razafindrabe,

Here’s how you achieve both of your requests:

1- repeat_count

You need to add a repeat_count column to your begin_repeat, this help article helps you how to achieve that:

https://support.kobotoolbox.org/group_repeat.html#controlling-the-loop-of-repetition-in-a-roster

2- position(..)

Create a new calculate question that uses the position(..) function to get the index of the iteration in the repeat-group
Reference that calculate field in a note

Here’s an example on how to achieve that:

1 Like

Thank you very much @hakan_cetinkaya. Your answers worked.

A note for future readers: for point two, the calculate has to be below/inside the begin_repeat group and not below/inside any other-sub group. I added it below my begin_group in my first attempt and that did not work, value stayed to 1. I guess that is probably because of the way the function position() evaluates itself.

2 Likes

That’s a good catch @kevin_razafindrabe :+1: your guess is absolutely correct

1 Like