Welcome to the LimeSurvey Community Forum

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

Array (numbers) question where all values for each row have to add up to 100

  • care4limesurvey
  • care4limesurvey's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 days 14 minutes ago #270433 by care4limesurvey
Please help us help you and fill where relevant:
Your LimeSurvey version: 6.5.3+240415
Own server or LimeSurvey hosting: hosted by my university
Survey theme/template:
==================
I want to create a survey questions where participants enter which type of food they dispose of through different channels. For this I used an array (numbers) with each of the food types in the rows and the different disposal routes in the columns. Participants shall then enter the percentage of each food type they dispose of through the respective disposal route as a numerical value. 
 
 

So far so good. Now i want to add the condition that fo reach row/food type all the values must add up to 100, because you can only dispose of 100% of food waste but not for example 120%. And I can't for the life of me figure out how to do it. I don't have any programming/coding skills so I read through the manuals. I tried this code in the question validation equation field: sum(Q5_SQ1.NAOK) == 100 and it does not work at all (I only tried it for the first subquestion as a test). I also always get the "undefined variable" notification.  

How do I get this to work?

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 day 18 hours ago #270435 by Joffm
Hi,
the first - obvious - error is:
You have y-axis codes "SQ001", "SQ002", ... and also x-axis codes "SQ001", "SQ002", ...
But in your validation equation you adress a subquestion code "SQ1".

Next: Your array is a two dimensional array; to adress a cell you need the y-axis code and the x-axis code
As you see here in the manual
[url] www.limesurvey.org/manual/ExpressionScri...code_variable_naming [/url]
If you are not sure, just activate the survey, and have a look at the responses table.

Now the solution that comes to mind at first is: "Sum all cells of a row" - for all rows
sum(Q1_SQ001_SQ001.NAOK,Q1_SQ001_SQ002.NAOK,Q1_SQ001_SQ003.NAOK,Q1_SQ001_SQ004.NAOK,Q1_SQ001_SQ005.NAOK,Q1_SQ001_SQ006.NAOK)==100 AND
sum(Q1_SQ002_SQ001.NAOK,Q1_SQ002_SQ002.NAOK,Q1_SQ002_SQ003.NAOK,Q1_SQ002_SQ004.NAOK,Q1_SQ002_SQ005.NAOK,Q1_SQ002_SQ006.NAOK)==100 AND
...



But if you read the manual here
[url] www.limesurvey.org/manual/ExpressionScri...%22that%22_variables [/url]
you can shorten this.
But only if you do the coding a bit different.
Instead of  "SQ00x" in both directions you may use "Y01", "Y02",... for the y-axis, and "X01", "X02",... for the x-axis.
This way you won't get confused later (what was y, what was x) when you import the data into your analysis tool.

Then you can validare by
sum(self.sq_Y01)==100 and sum(self.sq_Y02)==100 and sum(self.sq_Y03)==100 and ...

But beware: You will get an initial error.
When the question is displayed all sums are equal 0 (<>100). So there is an error.

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: care4limesurvey

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose