Merge items from two multiple select questions into one variable

I have two select_multiple questions authored on odk-xlsform that I need to join the selected answers into one variable. Example questions (1) and (2), are:
(1) Select all the fruits you ate today?
(a) Mango
(b) Orange
(c) Apple

(2) Select all the starch you ate today?
(a) Bread
(b) Pasta
(c ) Potatoes
(d) Rice

Question (1) a and b are selected
Question (2) b, c and d are selected

I need to join the answers from question 1 and those from question 2, to have a variable (all_food_eaten) with all the 5 answers (1a, 1b, 2b, 2c, and 2d).
I would like to use the variable (all_food_eaten) to form the basis for a repeat that repeats a count-selected number of times (in this case, 5 times). Each repeat has a set of questions for the five choices.

I will highly appreciate your assistance.

Thank you.

select_multiple results are stored as a space-separated string; eg "mango apple". So if you want to combine two of them you can just concat() the two results together - separated by a space - to effectively create a new select-multiple answer. Try this:

all_food_eaten: calculation = concat(${fruits}, ' ', ${starch})

You can then use ${all_food_eaten} just like a regular select_multiple result.

3 Likes