Welcome to the LimeSurvey Community Forum

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

How to sum radio button answers

  • Petteri66
  • Petteri66's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 years 9 months ago #185360 by Petteri66
How to sum radio button answers was created by Petteri66
Hi there,


I have 4 radio button questions (Q1, Q2, Q3, Q4) with each 4 answer possibilities (A1, A2, A3, A4).

Now I would like to sum e.g.:


sum(Q1_A4, Q2_A4, Q3_A1, Q4_A4)


I do get an error notice "undefined variable". What do I do wrong? Any hint is appreciated.


Petteri
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 9 months ago #185362 by holch
Replied by holch on topic How to sum radio button answers
You get this error, because there is no such thing as Q1_A1, Q1_A2, etc.

As you have a single choice question (radio button), you can access the question only via Q1 with the result being A1, A2, A3, etc., which you can also not add, because they are not numbers, but strings.

Sum does not make any sense here. What exactly are you trying to do? I think you don't really want to sum here anyway, but rather count, correct?

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.
  • Petteri66
  • Petteri66's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 years 9 months ago #185365 by Petteri66
Replied by Petteri66 on topic How to sum radio button answers
Hello Holch,

and thank you for the quick response.

I try to do following. I have 4 single questions with those 4 options. Each option is characteristic for one “style”. If the respondent choose e.g. in question 1 option 3, in question 2 option 1, in question 3 option 4 and in question 4 option 2, then “style 1“ gets the most “points”. The same method goes for the other 3 styles.

As you wrote, somehow I should count, how many “points” each style gets. How often option 1, option 2, option 3 and option 4 is chosen. Could I explain my problem?

Petteri
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 9 months ago #185368 by DenisChenu
Replied by DenisChenu on topic How to sum radio button answers
Maybe you can have a look at manual.limesurvey.org/Assessments

And then sum(Q1.valueNAOK,Q2.valueNAOK,Q3.valueNAOK)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • Petteri66
  • Petteri66's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 years 9 months ago #185378 by Petteri66
Replied by Petteri66 on topic How to sum radio button answers
Hello Denis,

and thanks for the message. I had already enabled assement modus. What i'm looking for is something like in the attached picture, where each answer option goes to specific "bucket" (blue, green... in my image) and then the sum for each bucket/color is counted.

Is this possible with radio buttons oder should I take an other approach with orher question type?


BR,

Petteri
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 9 months ago #185381 by Joffm
Replied by Joffm on topic How to sum radio button answers
Hi, Petteri,
you do it exactly as you would explain it.
"if an object goes to bucket 1, increase the sum of bucket 1 by 1"
"if an object goes to bucket 3, increase the sum of bucket 3 by 1".

"if an object goes to bucket 1" means "if the code of the object is "A1"

I use your example of the first post

I have 4 radio button questions (Q1, Q2, Q3, Q4) with each 4 answer possibilities (A1, A2, A3, A4).

Create 4 questions of type equation (sumA1, sumA2,...)
The above translated to an equation:
sumA1:
{sum(if(Q1=="A1",1,0),if(Q2=="A1",1,0),if(Q3=="A1",1,0),if(Q4=="A1",1,0))}
...
sumA3:
{sum(if(Q1=="A3",1,0),if(Q2=="A3",1,0),if(Q3=="A3",1,0),if(Q4=="A3",1,0))}

Joffm


Please, read the manual about the if-statement, implemented functions and the question types

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • Petteri66
  • Petteri66's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 years 9 months ago #185383 by Petteri66
Replied by Petteri66 on topic How to sum radio button answers
Hi Joffm,

great, thank you so much. That did the job.

I'll dive a bit deeper in this if-statement.

BR,

Petteri
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 9 months ago #185389 by tpartner
Replied by tpartner on topic How to sum radio button answers
The IF statements are similar to Excel...

Code:
{if(condition, returned if true, returned if false)}

You can also use nested IF statements to achieve IF ELSE (line breaks inserted for clarity)...

Code:
{if(q1 == 1, "Result 1", 
    if(q2 == 1, "Result 2", 
        if(q3 == 1, "Result 3", 
            if(q4 == 1, "Result 4", 
                "Result if none of the above true"))))}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • Petteri66
  • Petteri66's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 years 9 months ago #185400 by Petteri66
Replied by Petteri66 on topic How to sum radio button answers
Hi Tony,

yes, I noticed the similarity to excel, although == are for me not so familiar.

I will also test your solution, thank you.

Cherrs,

Petteri
The topic has been locked.
  • Petteri66
  • Petteri66's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 years 9 months ago #185430 by Petteri66
Replied by Petteri66 on topic How to sum radio button answers
Hi again,

I stil have one problem. The function sums only 3 out of 4 questions. The first one is left out. I think, I should have everything right and I can't see the mistake. Would you find the mistake in the following line:

sum(if(q1 == "A1", 1, 0), if(q2 == "A3", 1, 0), if(q3 == "A4", 1, 0), if(q4 == "A3", 1, 0))

BR,

Petteri
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 9 months ago #185431 by Joffm
Replied by Joffm on topic How to sum radio button answers
Sorry,nor can we see it without your survey, or better these questions and the equations.
So, please provide it as *.lss

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • Petteri66
  • Petteri66's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 years 9 months ago #185437 by Petteri66
Replied by Petteri66 on topic How to sum radio button answers
Hi Joffm,

enclosed you'll the questions as lsq-file.

Thank you,

Petteri
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose