Hi @ARIF_AZAD_KHAN
for the first calculation
the above calculation is to select the one of the listed options, thus the position for each option should remain the same position in the subsequent questions they are loop to.
Below are the explanation of the calculations
NOTE; members is the field name of the multiple choice field.
-
the if condition determines which option is choose in the multiple choice.
-
position(...), is the position of the option selected
-
-1, this holds the position of any option number in the multiple choice.
-
position(...)-1 holds the same position from the multiple choice, that is if
1=Khan
2=Fabla
3=Abdul
4=Fauzy
when you select 2 in the multiple choice you should be seeing 2 for Fabla when you loop it in subsequent questions.
-
count-selected(${members}), this count the total number of options selected in the multiple choice.
-
selected-at(${members}), position(...) -1) this is the field of the multiple choice and the position which is selected. so under members, which option is selected. so if option 4 is selected under members it will pick option 4 for the loop.
-
if position(...)-1 is less than count-selected(${members}), it should use selected-at(${members}), position(...)-1) but if position(...) -1 is greater than count-selected(${members}) then it should use -1 (which holds the position of the option number)
Example; if 2 options are selected say 1 and 5, the count-selected(${members}) will be be 2, so for the first option selected which is 1, it is less than the total number of options selected, so the selected-at(${members}, position(...) -1) will be used. which is option 2. for the second option, which is 5, but 5 is greater than the total number of options selected (2) so it will pick the -1 that his holding the position of the option number.
for the second calculation
NOTE; mem_post is the field name for the calculated field of the position of the multiple choice.
this is use to get the label from the choice sheet. when you are making reference to a selected option in a previous question, if you have a question like; select all your direct relative among the list
1=Khan
2=Fabla
3=Abdul
4=Fauzy
if you select option 2 and 4 in the above question and there is a subsequent question like;
on xlsform
how old is ${members}?
on ODK Collect
This question will display as how old is 2 and how old is 4
unless you put the calculation above.
jr:choice-name will look into your multiple field (members) and pick the calculated position for the selected option from the multiple choice and display the label of the selected option.
so when you do this calculation, your next question will now look like.
on xlsform
how old is ${mem_post}?
on ODK Collect
This question will display as how old is Fabla and how old is Fauzy
I believe this explanation is clear for you to understand the calculations in the sample file.
Thank you.
fabla2020@gmail.com