Enabling condition based on multi select answer order

Hi, I was wondering if there is anyway to reference the 1st answer selected when recording answer option for a multi select. Take the example below…

Q1. Please select your three favourite things from this list, where 1 is your first favourite, 2 is your second and 3 is your third favourite?

Q2. Why is [ANSWERNUMBER1] your favourite? [ask about answer number 1 from Q1 only]

Thanks!

Lachlan

Use 3 single select questions here filtering out the options chosen in the previous questions.

Hi Sergy,

Yes I had thought of that work around, just wondering if there was some function to reference the answer order value. - would be a nice thing to add in the future.

Thanks!

Lachlan

What you are suggesting now is a very different thing. You can already obtain the answer order by examining the selected items in the question’s value.

Mcq.Yes[0]
Will give you the code of the first selected item.

Mcq.Yes[1]
Will give you the code of the second selected item.

Etc. ( for the y/n multiselect with order tracking).

Best, Sergiy

Hi Sergy,

Yes this is what I an getting at. Is what you describe possible for regular checkbox multi select questions? or only for yes/no format?

Thanks!

Using the example that @sergiy told you

You can create a Variable of type String named ANSWERNUMBER1

In the expresion of this variable you should have:

Mcq[0]==1 ? "Text of the option 1" :
Mcq[0]==2 ? "Text of the option 2" :
Mcq[0]==3 ? "Text of the option 3" :
Mcq[0]==4 ? "Text of the option 4" :
Mcq[0]==5 ? "Text of the option 5" : "Text of the option 6"

In this case Mcq is the name of the variable of the question multi selection

Then in the text of your question you should have:
Q2. Why %ANSWERNUMBER1% is your favorite?

Also the enabling condition for Q2 should be IsAnswered(Q1)

Maybe this can help you @lachb

@kv700032 shows one approach, but unfortunately it is incompatible with multilingual questionnaires since the text hardcoded in the expression is not subjected to the translation and hence will always appear in one language.

This has been already discussed in the forum (in the context of random selection of an option) in the following thread:


(and possibly others).
The conclusion was to introduce another [technical] variable to indicate the language of the interview (which could still be useful in the analysis later).

My prior is that @lachb is working in a context of a multilingual questionnaire, hence I didn’t recommend that solution with duplicating the items hardwiring them in the syntax.

If you follow this route be especially careful with revisions to the questionnaire as you will need to revise the items in several places (questions and logic) to always keep them in sync.

1 Like

Thanks for the help! the example @kv700032 gives works well when the mcq has a fixed set of answers, however in my particular example it gives an error if the mcq is linked to a fixed roster. “== cannot be applied to roster vector…”

@sergiy I see what you mean about multiple languages. Generally I am creating system in English for testing and data export purpose with another language for fieldwork - so as we are just using this question piping I would set the strings in the variable in the fieldwork language - or even both with one language in brackets.

PS. also interesting to know how to access the language with the lng== function

Thanks!

@lachb

lng that was mentioned is not a function, but rather a variable name for a categorical single select question “What is the language of the interview?” that you put somewhere in the beginning of your questionnaire.

There is no (intentionally) access from the questionnaire logic to the translations that are uploaded. The logic of the survey should be abstract from the language of the interview.

Linked nature of the question complicates the matters a bit, but doesn’t make it impossible.
However, since the details matter, I suggest you create a minimal example with just the roster and the questions that matter and post the PDF preview of that minimal questionnaire into this thread.

You can also share the questionnaire with me for a review using the email that you know.

Thanks Sergiy, I shared an example with you. It doesn’t allow me to attached a pdf here.

Thanks!

For those of you playing along at home, here is the: PDF of the questionnaire

This has been an interesting challenge.

As @sergiy said, if you are going to work with multilingual questionnaires, my approach is not the right one to use.

But when researching more about a linked multiple-choice question, I found a way that could solve your problem, at least at this point.

In the expresion for the variable of type String named ANSWERNUMBER1
You should have:

Q3[0].ToString().Equals("_1") ? "Chocolate":
Q3[0].ToString().Equals("_2") ? "Strawberry" :
Q3[0].ToString().Equals("_3") ? "Vanilla" :
Q3[0].ToString().Equals("_4") ? "Cookies and Cream" :
Q3[0].ToString().Equals("_5") ? "Mango" : "Lime"

In this case Q3 is the name of the variable of the question multi selection

Then in the text of your question you should have:
Q4 - Why did you say that %ANSWERNUMBER1% was your favorite?

Also the enabling condition for Q4 should be IsAnswered(Q3)

If you going to work whit multilingual questionnaires, you must take the appropriate measures, taking into account what @sergiy mentioned

@kv700032 well done! that solution works very well. So is it because the data is stored as strings like “_1”, “_2” etc when multi select ranking questions are linked to a roster rather than numeric “1”, “2” when they are unlinked? Thanks!

Simplify! While the above works, a slightly shorter version would be:

Q3[0][0]==1 ? "Chocolate":
 Q3[0][0]==2 ? "Strawberry" :
 Q3[0][0]==3 ? "Vanilla" :
 Q3[0][0]==4 ? "Cookies and Cream" :
 Q3[0][0]==5 ? "Mango" : "Lime"

Which makes it apparent that we are referring to the first coordinate of the first selection (all indexing in arrays starts from zero in c#). You could use a macro to make it slightly more readable.

An even more readable version would rely on the fact that your codes are 1,2,3… (which will not be suitable if your codes were 7575, 47479, etc)

new[]{ "", "Chocolate", "Strawberry" , "Vanilla", "Cookies and Cream" , "Mango" , "Lime"}[Q3[0][0]]

Best, Sergiy

1 Like

@sergiy thanks for this collaboration.

This is perfect, but I would like to know what is the meaning of the second [0] in the expression Q3[0][0] ?
I understand it like a bidimensional array maybe like this
image
But I would like to know an interpretation about what each element stores in the matrix.

Again, thanks for this amazing collaboration!

C# supports (among other things) two similar, but not identical structures:

  • two dimensional arrays, a la M[5,3]
  • arrays of arrays, a la M[5][3], this is also known as jagged arrays, see details here

As per documentation, the value of a multiselect linked question is a jagged array.

Hi @sergiy,
I’m also in a similar situation to OP. i was hoping to be able to refer (by label) to the answers given on a multi-select question in a subsequent question’s question text. I assumed i’d be able refer to the first answer given to a question1 with something like: question1[0].Label but after doing some reading on this thread i realise this not possible, so now i’m trying to work out how to achieve the same ends with a different survey design…

In a post on this thread you suggest to:

“Use 3 single select questions here filtering out the options chosen in the previous questions”

…to solve this.

Could you expand on that? Or could you point us to an example that might help me understand what you’re suggesting we do?

Thanks in advance,
Ben

Labels of categories are not accessible from syntax, since the questionnaires are multilingual you have to always operate on the codes.

An example of filtering out categories can be seen in “Public example User questions and common patterns” questionnaire in the “Tourism seasons” section.

Best, Sergiy

thanks @sergiy. i appreciate your prompt reply!
i have worked out the approach w filtering the 3 single selects. that will get me out of the woods! :slight_smile:

Just to clarify, so there is no way to reference the labels of a select-question’s categories? how does the the question itself refer to the categories? they must be kept is some sort data structure like an array of {int key; string label;} pairs, no? or am i totally barking up the wrong tree?

Yes, they are kept in some data structure, but since it is private (not accessible from the user-code), the exact class is irrelevant.

Go one step backward. Why do you need to display a value of a multiselect question? What is the survey? What is the questionnaire fragment where this is used? Perhaps there is a different possibility of delivering the equivalent result (a workaround).