Error in filtering expression

Survey Solutions user Giselle del Carmen has sent the following question:

I have a single select question with 11 answer options. I want to filter the answer options displayed based on responses from previous questions. This is the syntax I’ve been trying but I get the error “expected”. How do I include several filter options for the same question?
(@optioncode==3 && p1_03==3) || ///
(@optioncode.InList(7,8,9,10,11) && p1_02==2) || ///
(@optioncode.InList(2,6) && p1_06==3) || ///
(@optioncode==7 && p1_05==3) ///

  1. no need to put /// at the end of the line like you do. the whole content is still one expression (aka one line). This is probably a habit inherited from Stata coding, where this is used to denote line continuation, but is redundant here. See also.

  2. it is not possible to establish syntax errors without knowing the types of all the identifiers involved, there is no such information in your post.

  3. Assuming that p1_* are single-select categorical questions, I don’t see anything suspicious from eyeballing your code, but the context matters. Also the error could be not in the filtering condition, but e.g. in enabling or validation condition.

  4. the error message was probably more specific and you’ve picked some text from it. original message could be more informative than your selection.

  5. it looks like options 1 and 4 will never be shown. It is unlikely that you meant that way, but it is not the reason for the error.

Best, Sergiy

Thank you Sergiy.

the syntax error I get is “Method name expected”. Yes p1_* are single-select categorical questions. I have no enabling or validation conditions for this particular question.

As for options 1-4 that I wasn’t including I added the last line in the code but am still getting an error. Basically I have a multi-select question with 12 options, however I only want certain answer options to show up given responses in other questions (p1_*)

(@optioncode==3 && p1_03==3) || ///
(@optioncode.InList(7,8,9,10,11) && p1_02==2) || ///
(@optioncode.InList(2,6) && p1_06==3) || ///
(@optioncode==7 && p1_05==3) ///
(@optioncode.InList(1,2,4,5,12) && p1_05!=3 && p1_02!=2 && p1_06!=3 && p1_03!=3)

This example shows how important it is:

  1. not to leave out any details even if you feel they are unrelated;
  2. not to congest the syntax with redundant elements, which reduce readability. Simplify!

Hope this solves it. Have a great weekend!