Welcome to the LimeSurvey Community Forum

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

Define variables in Expression Manager?

  • holch
  • holch's Avatar Topic Author
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #131384 by holch
I need to calculate a sum of points based on a 12x5 matrix question and 3 single choice questions.

The problem is that I can't use assessments, because each subquestion of the matrix question get different assessments on the different answers. So the equation is horribly long for that single question already, so I was wondering if I can create variables to keep the calculation clean instead of creating a huge amount of nested if statements.

I couldn't find anything in the manual, no example of this. So I guess it is not possible. But I thought I'd ask, maybe someone has a good solution.

My previous version looks like this:
Code:
{sum(CCEB1_1,CCEB1_2,if(CCEB1_3 == 1,4, if(CCEB1_3 == 2,5, if(CCEB1_3 == 3,6, if(CCEB1_3 == 4,7,0)))),if(CCEB1_4 == 1,4, if(CCEB1_4 == 2,7, if(CCEB1_4 == 3,9, if(CCEB1_4 == 4,9,0)))), if(CCEB1_5 == 1,3, if(CCEB1_5 == 2,4, if(CCEB1_5 == 3,4, if(CCEB1_5 == 4,4,0)))), if(CCEB1_6 == 1,2, if(CCEB1_6 == 2,2, if(CCEB1_6 == 3,2, if(CCEB1_6 == 4,2,0)))), if(CCEB1_7 == 1,2, if(CCEB1_7 == 2,2, if(CCEB1_7 == 3,2, if(CCEB1_7 == 4,2,0)))), if(CCEB1_8 == 1,4, if(CCEB1_8 == 2,4, if(CCEB1_8 == 3,4, if(CCEB1_8 == 4,4,0)))), if(CCEB1_9 == 1,2, if(CCEB1_9 == 2,2, if(CCEB1_9 == 3,2, if(CCEB1_9 == 4,2,0)))),CCEB2)}
Now it had become worse, because in the example above, for some of the subquestions above I could use the answer code as points, for others I had to apply different values via if loops. And then in this previous version there was only one additional single choice question, wherre I also could use the answer code as points.

Now all subquestions require their own if loops to attribute the points and I also need some if loops for the single choice questions and I feel the code written in one big piece is becoming a little big and complicated.

My other solution would be to write each question in a separte equation and then add them up in another equation. But I would find it cleaner to be able to break things up in only one equation question.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #131402 by tpartner
Replied by tpartner on topic Define variables in Expression Manager?
Hi Holch, given the different "score" levels for sub-questions, I don't see any other way to do it in a single equation question.

Having said that, my preference would be to a separate equation question for each sub-question "score". I would find that easier to handle.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • holch
  • holch's Avatar Topic Author
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #131416 by holch
Replied by holch on topic Define variables in Expression Manager?
Yeah, I was thinking about that if there is no such thing as variables in EM.

I don't really like the idea of having 16 equation questions for those 4 questions (Question 1 with 12 subquestions plus 3 other questions plus the equation that will calculate the summary).

Well, but I guess it is the cleanest option.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose