Asking question for all unique pairings of select_multiple choices

Hi all, I am having trouble figuring out how to ask a question for all unique pairings of choices made in a select_multiple. I have uploaded a sample form at the end of this post and provide examples below which will hopefully make my desired result clear.

Within my sample form, I first use a select_multiple to ask which groups are present in a location (the variable "groups", row 2). I would then like to ask a subsequent question (the variable "relation", row 7) about the relationship between each unique pair of groups, based on the choices selected in "groups". For example, if Groups A, C, and D were selected in "groups", I'd like to ask about the relationship between 1) Group A and C, 2) Group A and D, and 3) Group C and D.

The attached form includes my initial attempt to use nested repeats to do this, but the nested repeats end up asking the "relation" question for the same group paired and for duplicate pairings. I.e., for the example above, the current sample form asks about 1) Group A and A, 2) Group A and C, 3) Group A and D, 4) Group C and A, 5) Group C and C.... and so on.

As a note, my full form has a large number of choices for "groups", so I'd prefer to do this using repeats if possible (rather than relevancy constraints).

I'm struggling to wrap my head around how to approach this to include only unique pairings. Appreciate any help!

testform.xlsx (12.4 KB)

Hi @paycemadden,

Welcome to ODK Forum, if you have a moment, feel free to introduce yourself here.

This is an interesting challenge you are trying to solve. Let's consider enumerator selects all four groups, following are the combinations that needs to be created:

Given that we can see

  • repeat_count of outer repeat = length of selected groups - 1 (in this case 3)
  • repeat_count of inner repeat = length of selected groups - position of outer repeat (in this case first 3, then 2 and then 1)

I have attached a working Form below.

Few suggestions:

  • When I have to design a complex Form like that, I like to be verbose by creating extra variables to keep my formulas simple. In the attached Form I have created selectedLength, index i and index j to help me understand the flow of the Form.
  • I use note type to see the values of calculated fields, once I am satisfied with the working of the Form, I change them to calculate to hide them.
  • Added a nested group in each repeat with relevancy so that when number of select group change, extra repeats are not shown: see this for more details.
  • We have XLSForm template that makes it easier to design Form, you can download it from https://xlsform.org/en/ref-table/

testform.xlsx (12.5 KB)

Hi Sadiq - apologies for my slow response, I was pulled onto another task the past week. Thank you very much for this great solution, it works perfectly. Thank you for the clear explanation as well!