Welcome to the LimeSurvey Community Forum

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

EM to sum question type array

  • outofgamut
  • outofgamut's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 7 months ago #123426 by outofgamut
EM to sum question type array was created by outofgamut
Hi all,

I am trying to implement a simple questionnaire score.

9 questions with 4 answer each: (never (0), some (1), often (2), always (3)). I would like EM to assign the numbers in parenthesis to those answer and allow me to do sums.

I have used array as the radio buttons automatically only allow exactly one answer per row but I can't make LimeSurvey assign values to my columns.

Is there a way to easily achieve what I am after?
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 7 months ago #123433 by holch
Replied by holch on topic EM to sum question type array
Well, there are two options. You assign assment values to your questions, or in your case probably easier, you use the code for each answer option and give them the value you want to calculate with already.

Later you can write a simple expression that sums the responses to each subquestion.

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

The following user(s) said Thank You: outofgamut
The topic has been locked.
  • outofgamut
  • outofgamut's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 7 months ago #123444 by outofgamut
Replied by outofgamut on topic EM to sum question type array
Thanks, holch.

I looked at every part of the manual before I posted but didn't get far. I initially had tried assessment values but EM did not incorporate them when I used sum().

I'd love to use your second option - how do I assign values to answer options that EM can evaluate?
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 7 months ago - 8 years 7 months ago #123449 by holch
Replied by holch on topic EM to sum question type array
OK. Here we go with an example.

I show you both the option I mentioned.

1. Using the assessment values (Assessment values 0, 1, 2, 3)
2. Using the answer codes (To show the difference I used the codes 1, 2, 3, 4)

I used an array question for this, but this can be done with seperate questions as well.

To access the value of each subquesiton, you need to use
Code:
questioncode_subquestioncode.value

In my case, as I call the question G1Q1 and have 3 subquestions, these are the codes you need to use:
Code:
G1Q1_1.value
G1Q1_2.value
G1Q1_3.value

Without .value at the end you will access the response code.

Have a look at the attached survey and play around and see the effects.

You could of course also give the 0, 1, 2, 3 directly to the response code and only sum those.

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

Last edit: 8 years 7 months ago by holch.
The following user(s) said Thank You: outofgamut
The topic has been locked.
  • outofgamut
  • outofgamut's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 7 months ago #123452 by outofgamut
Replied by outofgamut on topic EM to sum question type array
That was very helpful, holch - thanks a lot! Quite a few things have become clearer to me now.

I also need to assess the number of ticks in columns. I am evaluating the array's column like
Code:
{sum(that.myarray.sq_2.NAOK)}
but that returns answers that seem to have little to do with what has been entered into the array. I've also tried using "count" instead of "sum" but that shows either "1" or "0" it seems.

Am I mixing something up?
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 7 months ago #123461 by holch
Replied by holch on topic EM to sum question type array
I am not aware that EM accesses columns.

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.
  • outofgamut
  • outofgamut's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 7 months ago #123464 by outofgamut
Replied by outofgamut on topic EM to sum question type array
Hm. I've worked around it now. But in the manual it says:

You can also use these to get row and column totals. Say you have a array of numbers with rows A-E and columns 1-5.
What is the grand total? {sum(self.NAOK)}
What is the total of row B? {sum(self.sq_B.NAOK)}
What is the total of column 3? {sum(self.sq_3.NAOK)}
The 'that' variable is like the 'self' variable, but lets you refer to other questions. Its syntax is:
that.qname
that.qname.suffix
that.qname.sub-selector
that.qname.sub-selector.suffix
qname is the question name without any sub-question extensions. So, say you create a question 'q1', that is its qname
Examples:
Has any part of question q1 been answered? {count(that.q1.NAOK)>0}
What is the assessment score for q2? {sum(that.q2.NAOK)}
What is the grand total of q3? {sum(that.q3.NAOK)}
What is the total of row C in q4? {sum(that.q4.sq_C.NAOK)}
What is the total of column 2 in q4? {sum(that.q4.sq_2.NAOK)}
The 'self' and 'that' variables can be used in any relevance, validation, or tailoring.
The one caveat is that when you use the Show Logic File feature, it will show you the expanded value of 'self' and 'that'. This lets you see the actual equation that will be generated so that you (and Expression Manager) can validate that the variables exist. This may seem confusing since you may see quite lenghty equations. However, if you edit the question, you will see the original equation using 'self' and/or 'that'

The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose