Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Complicated skip / display function with arrays.

  • nique
  • nique's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 5 months ago #143341 by nique
I apologise in advance for this complicated skip function. I think I just need some help with the logic as I know I could create 1000 conditions to make this work but I envision a lot of errors appearing because of that.

I have two array questions which flow onto a multiple choice question.

The logic for the multiple choice question presentation is as follows
- DO NOT display if 'not at all' or 'don't know' selected for all categories in H20
- DO NOT display if not a single 'yes' is selected in H21

Therefore H22 is displayed if the participant has varied responses to H20 and 21 but is removed if the participant says a lot of no's.

I have attached the 3 questions in the survey which need this logic applied. I am also happy for suggestions on how to change the questioning or presentation of these questions which might make the presentation logic a little easier.

Thank you in advance.
Attachments:
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 5 months ago #143343 by Joffm
Hi, nique,
I would just sum it up in two equations, like
SumH20: {sum(if(H20_SQ001=="NACode",1,0),if(H20_SQ001=="DKCode",1,0),,if(H20_SQ002=="DKCode",1,0),,if(H20_SQ002=="DKCode",1,0),...}
SumH21: {sum(if(H21_SQ001=="YesCode",1,0),if(H21...
So you display H22, if
(SumH20<>count of categories of H20) and (SumH21>0)

Best regards
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • nique
  • nique's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 5 months ago #143409 by nique
Hi Joffm,

Thank you for that. I never even considered using a hidden equation to circumvent the conditions issue.

Can I just ask for clarification on the display function. I currently have if(SumH20<6), just simplifying to one question, but I get an error around the if code. I have struggled for a while with the display function in Expression Manager so your help there is greatly appreciated.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 5 months ago - 7 years 5 months ago #143423 by tpartner
The relevance equation is intended to be a boolean statement. If the statement is true, the question is shown.

In your case, I would insert two hidden equation questions to store the "results" of the first two arrays.

The first equation question (let's call it "equationH20Sum") would sum all of the rows in H20 that are not "Not at all" or "Don't know":
Code:
{sum((H20_1 != '' &amp;&amp; H20_1 != 1 &amp;&amp; H20_1 != 999), (H20_2 != '' &amp;&amp; H20_2 != 1 &amp;&amp; H20_2 != 999), (H20_3 != '' &amp;&amp; H20_3 != 1 &amp;&amp; H20_3 != 999), (H20_4 != '' &amp;&amp; H20_4 != 1 &amp;&amp; H20_4 != 999), (H20_5 != '' &amp;&amp; H20_5 != 1 &amp;&amp; H20_5 != 999), (H20_6 != '' &amp;&amp; H20_6 != 1 &amp;&amp; H20_6 != 999))}

The second equation question (let's call it "equationH21Sum") would sum all of the rows in H21 that are "Yes":
Code:
{sum(H21_1 == 1, H21_2 == 1, H21_3 == 1, H21_4 == 1, H21_5 == 1, H21_6 == 1, H21_7 == 1, H21_8 == 1, H21_9 == 1, H21_10 == 1)}

Then the relevance for H22 would be:
Code:
equationH20Sum == 6 &amp;&amp; equationH21Sum > 0

Sample survey attached:

File Attachment:

File Name: nique-test_TP.lss
File Size:33 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 7 years 5 months ago by tpartner.
The following user(s) said Thank You: nique
The topic has been locked.
  • nique
  • nique's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 5 months ago #143460 by nique
Thanks tpartner. The final relevance equation is exactly what I was after.

I also made some adjustments to the code so that if at least one other option, apart from don't know and not at all was selected in H20, then H22 would display.

I changed the code for another similar question I have where if H21 == 0 then displayed. I understand why logically it would appear on the page (nothing has been selected therefore it is correct) but I want it to display when no Yes's have been selected. I have it moved to a new group so it would only appear on the next page after they answer H21 but I just wanted to check if that is the best way to do it or if there is something else I can add to EM.

It works either way but I want to learn / have the code be cleaner.

Thanks again for all your help.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 5 months ago #143472 by tpartner
To check that H21 has been fully answered, you can use something like this (where H21 has 10 subquestions):
Code:
count(that.H21.NAOK) == 10

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose