If Formula does not work with "select_many" question!

1. What is the problem? Be very detailed.
I have a "select_many" question and I want to refect the selected options in a "note" after that question but with different results (labels not values). for example:

Q1 (select_many): "Chose from the list below the chemical elements which have an Atomic weight more than 20 u":
Option 1: "Hydrogen"
Option 2: "Fluorine"
Option 3: "Neon"
Option 4: "Calcium"
Option 5: "Lutetium"

Let's say that the responder chose: Option 3 + 4 + 5. I want the form to transfer the selected options to other labels (names not values) and present them in a "note" message as below:

Q2 (Calculation): which I don't know about

Q3 (note): "According to your answer, "Ne-which represents Neon element", "Ca-which represents Calcium element", "Lu-which represents Lutetium element" weighs more than 20 u.

2. What app or server are you using and on what device and operating system? Include version numbers.
I'm using Kobo toolbox on windows 10 operation system

3. What you have you tried to fix the problem?
I tried to use If formula but it always shows me one of two results:
1- only one output in case I CHOOSE one answer
2- shows me nothing if I choose more

4. What steps can we take to reproduce the problem?
Can we create a formula to present what I ask for?
5. Anything else we should know or have? If you have a test form or screenshots or logs, attach below.
I would appreciate your support!!!!!!!!!!!!!!!

Hi @syria_son, welcome to the forum, we're glad you're here! You'll want to use the jr:choice-name() form function. Click "Show details" at the end of the linked documentation to see an example. I think you're case might be helped by something like the below. I can see how it would be frustrating to have an extra question for every possible response. That is, if Q1 has 5 options then you'd have 5 calculate questions and the note question in order to capture every possibility. Unfortunately, I'm not aware of a more efficient way to do this. It also looks like you want to pull both the name and also the label for each answer?

|           type            |      name      |                  label                  |                      calculation                       |
| select_multiple q1choices | Q1             | Choose from the list…                   |                                                        |
| calculate                 | q1_selection_1 |                                         | jr:choice-name( selected-at(${Q1}, 0), '${q1choices}') |
| calculate                 | q1_selection_2 |                                         | jr:choice-name( selected-at(${Q1}, 1), '${q1choices}') |
| note                      | my_note        | ${q1_selection_1} and ${q1_selection_1} |                                                        |

Hello @syria_son,

This functionality got me scratching my head - In a good way... So I tried a different method using one repeat with one calculate to keep track of the options. it could have been text as well, but the calculate keeps the repeat invisible to the user.

The rest of the mechanics use jr:choice-name to get labels, concat to introduce a kind of separator and outside the repeat a join(separate, list variable) t o put everything together in one readable text or note as you wish.

One know issue with this, is if user goes back and edits the choices, then the repeat updates automatically but the separators won't... You can tweak this around as you judge suitable

You can download the form here and try it on your own

Happy ODKing,
Jules R

1 Like

Nice solution!

A minor suggestion/improvement is that you can exploit the join()'s separator, instead of manually adding one inside the repeat. Have a play with this:

UPM_Maintenance3.xlsx (10.7 KB)

Thank you @Xiphware for the suggestion.

I had tried that, but the issue with it lies within the repeat controlled by select_multiple. E.g.: when user change their mind and modifies the selection, the repeat won't update automatically, unless through the manual removal (screen long press) of template spaces generated from the repeat_count value (in my case was set to automatic from the count-selected items), so whenever this happens, the join() would leave the separators in the text note while removing the user changes. The repeat was also set to invisible since it only contains calculate fields making it impossible to perform manual removals...and that's why I tried to embed the separators inside the repeat instead....

Give it a try and do let me know if you have a solution to that already... it's been my frustration for quite some time..

With regards,
Jules R

Hmm... I would think it should, but do know from experience that there a quirks and differences (between Collect and Enketo) when having repeat groups without actual displayed controls... Lemme play around a bit more too! Cheers. :slight_smile:

Thank you all guys for this amazing contribution, it helped me a lot in having a different thoughts regarding my forms. Honestly I was using the following calculation:

concat(jr:choice-name(selected-at(${Q1}, 0), '${Q1}'), ', ', jr:choice-name(selected-at(${Q1}, 1), '${Q1}'), ', ', jr:choice-name(selected-at(${Q1}, 2), '${Q1}'))

This calculation was giving me a headache because if I had more options it will be more complicated

Thanks to @jules_rugwiro and his calculation, I could make that in a better and simpler way:grin:

However, my main problem is presenting the same option as it is in the question (Q1), which I don't want to. What I want to have is a twisted result in the final message so different from the option I chose (label and value).

So can we -for example- change the third part of the calculation in the following formula and put a simple text (totally different) instead of "Q1"

concat('"', jr:choice-name(selected-at(${Q1},position(..)-1),:point_right:'${Q1}'),'"')

or in my calculation:

concat(jr:choice-name(selected-at(${Q1}, 0), :point_right:'${Q1}'), ', ', jr:choice-name(selected-at(${Q1}, 1), :point_right:'${Q1}'), ', ', jr:choice-name(selected-at(${Q1}, 2), :point_right:'${Q1}'))

I'm so sorry if I'm making it so complicated or if I didn't make what I want clear before.
Thanks again for you help @Xiphware @jules_rugwiro @danbjoseph