countSelected works in constraint column, but it does not in calculation column

I am trying to count the number of selections made by users with a select_multiple variable. I tried different solutions and found the followings:

  1. In the display.prompt.text column, I can use {{ data.<select_multiple_variable_name>.length }} to get the total selections.

  2. In the constraint column, countSelected(data(‘<select_multiple_variable_name>’)) works. (e.g. countSelected(data(‘my_variable’))>=3)

However, I don’t just want to display the count or use it for validation. I want to store the count in a variable and use it in calculation. I tried to use both the above solutions in calculation column and neither works.

Could somebody please advise me how can I get the count of selections made in a select_multiple prompt type.

When you say that you want to store the count and tried the calculation column – did you try to assign a variable using this calculation? This is how you would do such an operation.

Yes, I set the assign in the ‘type’ column, variable name in the ‘name’ column and the following expression in the ‘calculation’ column.

countSelected(data(‘variable_name_of_select_multiple_type’)).

When I look at the newly assign variable through display.prompt.text, nothings showed up. It looks like that {{ data.newly_assigned_variable }}

I put select_multiple, assign, and note(display) lines between begin screen and end screen to see the update directly. (when I tested without the begin screen and end screen, the same result came out.)

Dear elmps2018, I found my problem. I did not give a chance to run assign command. I tested again removing begin and end screens. This time, I add a new line with note type after assign command. So, when the control arrive the note line, the assign line has already run, and consequently show the variable in note screen.

Anyway, thank you so for your advice. Because of it, I became confident that the assign command and countSelected function would work together.