Constraint that data cannot be repeated in same repeat group

I would like to be able to compare data that has been collected within the same repeat group of questions.

For example:
A repeated set of questions that asks the same question: "What are some of your favourite colours / numbers?".
Answer 1: "red" / "3"
Answer 2. "green" / "5"
Answer 3. "green" / "5"
Constraint warning! - "You have entered the same text / numeric response again. Please choose another."

Is this possible using a repeat group or will I need to lay out the same question multiple times with increasingly complex constraint arguments: ". != ${answer_1} & . != ${answer_2} & ...".

Many thanks,


Hi Stuart,

This is possible if you put something like this as a relevancy on a dead-end question that has your constraint warning above as the label:

count(/color_survey/group_name[(position(.) < position(current()/..)) and (./color = current()/../color)]) != 0

So you are counting the number of previous loops (position(.) < position(current()/..)) where the same color was chosen ( (./color = current()/../color)] ) and if that count is not 0, your roadblock question comes up and prevents moving forward.


Thanks Jason,

that is exactly what I was looking for.



Hello @Jason_Ives @stuart_stevenson

I couldn't actually get the meaning of "count(/color_survey/group_name[(position(.) < position(current()/..)) and (./color = current()/../color)]) != 0"

Can anyone please explain what is "color_survey", "group_name", "color" in this case?


Hi Likhon,

Let me preface this be saying I'm not 100% sure this is still the best solution, I haven't tested the last few ODK releases so I don't really know if built-in functionality for this has ever been introduced.

Those elements are references to the XML structure of the survey. So "color_survey" would be the survey name, and "group_name" would be the name of the repeating group within the survey that contains the "What are some of your favourite colours / numbers?" question. You can think of it as the path to the question.

If you are unsure what your path is, you can always check it by opening the XML survey file and searching for your question name. In particular the bind nodeset entry should have the path to your question. From there you can determine what repeating group the question is in, what the name of your survey is, etc - and structure the above code accordingly. Hopefully that helps.


1 Like