HOW TO
Select Multiple Questions in Survey123 store the names of the selected choices as a CSV string, i.e., Option1,Option2,Option3,Option4. While it is useful to store the unique names of choices, sometimes we want to easily access a list of the labels of selected choices. For example, the plant names Acacia, Banksia, Callistemon, and Eucalyptus.
We have more flexibility and freedom with naming conventions when choosing Labels compared to Names. To improve readability, the CSV string also must be reformatted to include spaces between the options, which is time-consuming when done by hand. It is possible to create a new object in an XLSForm to reformat the selected choices using the Label instead of the Name. We can do this by combining a series of formulas in the Calculation field. The scientific and common names of some Australian plants are used in this example.
As we will be combining multiple functions, it is a good idea to start at the endpoint and build outwards. To begin with we will use the jr:choice-name() and selected-at() functions:
jr:choice-name(selected-at(${PlantSpeciesCSV},0), '${PlantSpeciesCSV}')
We can use the concat() function to join all the labels of all selected answers into one string, with our desired punctuation.
concat(jr:choice-name(selected-at(${PlantSpeciesCSV},0), '${PlantSpeciesCSV}'), ', ', jr:choice-name(selected-at(${PlantSpeciesCSV},1), '${PlantSpeciesCSV}'), ', ', jr:choice-name(selected-at(${PlantSpeciesCSV},2), '${PlantSpeciesCSV}'), ', and ', jr:choice-name(selected-at(${PlantSpeciesCSV},3), '${PlantSpeciesCSV}'))
From here we need to create a series of nested if statements to filter our labels by the number of answers chosen. We set the condition for each if statement to return true if we have a value or choice at the given number. Counting starts from zero, so '3' will return the fourth selected choice. For example, if we want to display the labels when we have selected three choices, we set the condition to selected-at(${PlantSpeciesCSV},2). If this condition returns TRUE, then our concatenated string is outputted, i.e. Gold Dust Wattle, Silver Banksia, and Willow Bottlebrush. If the condition is false, then we test the next if statement. This continues until the condition returns TRUE. If none of the conditions are met, then we can specify that a custom statement such as, No Plants Observed is returned, indicating to us that no choices were selected.
if(selected-at($PlantSpeciesCSV},3),concat(jr:choice-name(selected-at(${PlantSpeciesCSV},0), '${PlantSpeciesCSV}'), ', ',
jr:choice-name(selected-at(${PlantSpeciesCSV},1), '${PlantSpeciesCSV}'), ', ', jr:choice-name(selected-at(${PlantSpeciesCSV},2), '${PlantSpeciesCSV}'), ', and ', jr:choice-name(selected-at(${PlantSpeciesCSV},3),
'${PlantSpeciesCSV}')), if(selected-at($PlantSpeciesCSV},2),concat(jr:choice-name(selected-at(${PlantSpeciesCSV},0), '${PlantSpeciesCSV}'), ', ',
jr:choice-name(selected-at(${PlantSpeciesCSV},1), '${PlantSpeciesCSV}'), 'and ', jr:choice-name(selected-at
(${PlantSpeciesCSV},2), '${PlantSpeciesCSV}')), if(selected-at($PlantSpeciesCSV},1),concat(jr:choice-name(selected-at(${PlantSpeciesCSV},0), '${PlantSpeciesCSV}'), 'and ',
jr:choice-name(selected-at(${PlantSpeciesCSV},1), '${PlantSpeciesCSV}')), if(selected-at($PlantSpeciesCSV},0),jr:choice-name(selected-at(${PlantSpeciesCSV},0), '${PlantSpeciesCSV}'), 'No Plants Observed'))))
A couple of things to note:
Article ID: 000031066
Get help from ArcGIS experts
Download the Esri Support App