Multi-select in hidden Values

Hi Guys,

I am wondering what is the best way to go about incorporating these instructions as a hidden value:

  • IF '6' is not selected, then score is '1'
  • IF '6' is selected AND any other option is selected, then score is '3'
  • IF '6' is the only option selected, then score is '5'

So far I have the following Xpath expressions but it is not working. I am wondering do I need to add an or between each instruction?:

Hi Shawn,

You can use a combination of selected and count-selected functions to implement your logic.

From the documentation here, selected-at(question,choice1) returns true if choice1 is selected while count-selected returns the total number of choices selected. So the conditions you outlined can be programatically represented as -

  • IF ‘6’ is not selected:
    selected(/data/multi_select_question,"choice_6") = false

  • IF ‘6’ is selected AND any other option is selected:
    selected(/data/multi_select_question,"choice_6") = true and count-selected(/data/multi_select_question) > 1

  • IF ‘6’ is the only option selected:
    selected(/data/multi_select_question,"choice_6") = true and count-selected(/data/multi_select_question) = 1

All these conditions can be consolidated in a single nested if statement with their respective score values like this -

if(selected(/data/multi_select_question,"choice_6"), if(count-selected(/data/multi_select_question)=1, 5, 3),1)

Hope it helps, let me know if you have further questions.

1 Like

Thanks, I will give it a try now

Thanks Shubham, it worked like a charm! :slightly_smiling_face: