# Avoiding duplicate selection in repeat group

**URL:** <https://forum.getodk.org/t/avoiding-duplicate-selection-in-repeat-group/9900>\
**Category:** Support\
**Tags:** odk-aggregate, odk-xlsform\
**Created:** [September 19, 2017, 2:23pm UTC](https://forum.getodk.org/t/avoiding-duplicate-selection-in-repeat-group/9900 "2017-09-19T14:23:11Z")\
**Posts on this page:** 1\
**Showing post:** 22

<div class="post-metadata">

**Author:** ![LN](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ln/32/1605_2.png) [@LN](https://forum.getodk.org/u/LN)\
**Post date:** [October 14, 2022, 7:00pm UTC](https://forum.getodk.org/t/avoiding-duplicate-selection-in-repeat-group/9900/22 "2022-10-14T19:00:12Z")

</div>

> [@Rusti](#):
>
> I am using numerical codes for the names, so I have a species of '7' and a species of '73' which is causing the issue, is this possible?

Yes, absolutely, that form does assume that each value is unique and not contained in other values. This is a reasonable assumption for selects but you're right that it doesn't make sense for arbitrary strings or integers.

[This form](https://docs.google.com/spreadsheets/d/1IC_egzIB63W4-VwQXNZG87BPHcYnkLBAMOpPeELacXA/edit#gid=0) shows an alternative using an XPath filter expression (the stuff in the square brackets):

`join(' ', ${rpt}[position != current()/../position]/id)`

That says to join all of the `id` values for repeats which are not the current one. I tend to try to avoid XPath in examples but in this case it may actually be a clearer solution all around and less risky because it doesn't assume anything about values entered. What do you think?

I didn't look at @bdra2778's example above in great detail but I think the concept works as well. It uses a parallel repeat to compare every prior value. Do note that it would be slower with a bigger repeat. @bdra2778 there also is one limitation I can think of: because your repeat count is `position(..)-1`, you won't immediately detect duplicates if someone comes back to edit an answer. For example, if they enter in 2, 6, 7 and then go back to change the 2 to a 7, I believe that will be accepted. However, on validation, the second 7 will show a constraint failure. This is not a big deal but I did want to point it out.

---

_[View the full topic](https://forum.getodk.org/t/avoiding-duplicate-selection-in-repeat-group/9900)._
