Avoiding duplicate selection in repeat group

What is the problem? Please be detailed.
I am creating a form where i have a repeat group. Users will enter "Item" in the field. When they add another field in the group, I want them to avoid selecting same item that they selected in the first field. I would appreciate a solution for this problem
I am using xls form for this purpose.

Your question is like.
If i have 5 options(a,b,c,d,e) and i select c so next time i will see again 5 options however i am not able to select optionc c.
AM i correct?
If you share more information that will be more helpful for us.


Suppose out of following items from the dropdown list user selects -"Broom"
*** Broom**

  • Detergent
  • Brush
  • Pipe

Second field in the repeat group , same lists but if user selects "Broom" again it should show some validation error or completely restrict inputting same name in the field.

I hope that is more clear!

1 Like


As far I know, repeat group will only load the same form without any changes to fill out. You can try to find an alternative solution if you would like to restrict anything on your next form. you can create duplicate forms and load them based on logics, and on those forms, you will be able to restrict a number of options/answers to be displayed.



Please have a look at the attached example which is about avoiding duplicates answers in a repeat group.
Good luck.

repeat_groups_avoid_duplicates.xls (34 KB)


Hi Souirji,

learnt something new. I had a wrong concept.



@Souirji_Abdelghani Awesome!!! :smiley: Thank you very much for the solution! This was exactly what i was looking for!

1 Like

Thanks for this. The form is running perfectly but when you download the data, the database is empty. I dont know what could be the reason? I have tried a similar looped indexed types of questions but i am loosing data for the repeat groups.

1 Like

@Levie_Nkhoma, what server/platform (and version) are you using to gather the data?

Can anyone help me with this error?
I would like to avoid duplicate selection in the items list (row 15, survey sheet in attached xls) and tried as mentioned in repeat_groups_avoid_duplicates xls file by @Souirji_Avdelghani. But it didn't work and replied as invalid in constraint expression when the attached xls was deployed into kobo toolbox.
Could you please check in the attached xls form and help me with the correct expression in constraint for avoiding of duplicate selection to the items.
Thanks in advance.Kobo_Covid19 Response_test.xlsx (20.8 KB)

@mhl, You have a mistake in form name that used in your constraint, replace white space with underscore and it works.


Hi @A.N.M_AL-IMRAN, @Souirji_Abdelghani

Please have a look at the attached example, which is based on the case above of the letters A, B, C, D.

I used substring-after() to compare the duplicate values ​​with the selected answer in ODK.

I hope this file is useful.

avoiding_duplicate_selection_in_repeat_group.xlsx (12.6 KB)

Hi, I tried to use this same example, without making any modification and is not working. Do you know what could be the reason?
I am looking for a similar example where 3 select groups are nested in a repeat loop. First select age groups (<18,>18), then sex (male, female), then education (primary school, high school, university, etc), and finally an integer to account for the number of individuals having these characteristics. Any help is more than welcome!

Hi I am linking this in here as an alternative which worked for me. https://community.kobotoolbox.org/t/preventing-duplicate-entries-in-a-repeat-loop

This solution won't work if the full form is re-evaluated because the result of the join will include all values saved and the validation will fail for every question. Enketo seems to sometimes do a full re-evaluation but not always (this is something we intend to harmonize between Collect and Enketo at some point). Collect always does the full re-evaluation so the form will not work.

I believe this form works in all cases across Collect and Enketo.

1 Like

Thanks LN I will take a look and update.

Hi LN, this form gives an issue on save which is the earlier problem i was having. Give the error 'Sorry, this response is invalid!' which is why I looked for an alternative solution as i could not work out what the problem was. Please let me know if there is something i can update. It seems to always be on the second option on save


Acá dejo un ejemplo más, espero que sea lo que buscan,

Detectar ID Duplicado.xlsx (13.9 KB)


Hi LN, i have done some tests on this form (original link i posted) and it seems to work. What part would give an error - on save error, or would I get data loss/error occurring. It would help me to know what to look for.

Unfortunately I still cannot get the form you linked in to run correctly.


The form I posted was indeed in a really weird state, sorry about that. Could you take a look again? The important components are that there's a join calculation outside of the repeat that aggregates all of the values and then there's a calculation inside the repeat that takes that aggregate and removes the current choice from it:

concat(substring-before(${so_far_outside}, ${choice}), substring-after(${so_far_outside}, ${choice}))

For example, if a, c and d are selected, the so_far_outside string will be a c d and in the context of the third repeat, so_far will be a c which allows d to be selected. Similarly, in the context of the first repeat, so_far will be c d, allowing a to be selected.

I looked at the form you posted and I don't understand how it would work. I tried it quickly in Enketo and as soon as I put in three codes, no matter what they are, I get a failure when I try to validate. This is because the join expression includes the current question's code, thus making the constraint fail. Have you made successful submissions from that form? Additionally, the substring expression doesn't make sense because it's always removing codes from the end rather than removing the value corresponding to the current repeat. You can change the label for Q1 to So far: ${C3} to see the value that the constraint is being evaluated against.