- Posts: 29
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
How to sum radio button answers
- Petteri66
- Topic Author
- Offline
- Junior Member
Less
More
4 years 10 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
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11658
- Thank you received: 2742
4 years 10 months ago #185362
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
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?
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
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 29
- Thank you received: 0
4 years 10 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
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
- Away
- LimeSurvey Community Team
Less
More
- Posts: 13645
- Thank you received: 2491
4 years 10 months ago #185368
by DenisChenu
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.
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)
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
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 29
- Thank you received: 0
4 years 10 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
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
Attachments:
The topic has been locked.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12925
- Thank you received: 3977
4 years 10 months ago #185381
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
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
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
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
Create 4 questions of type equation (sumA1, sumA2,...)I have 4 radio button questions (Q1, Q2, Q3, Q4) with each 4 answer possibilities (A1, A2, A3, A4).
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
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 29
- Thank you received: 0
4 years 10 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
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
4 years 10 months ago #185389
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic How to sum radio button answers
The IF statements are similar to Excel...
You can also use nested IF statements to achieve IF ELSE (line breaks inserted for clarity)...
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
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 29
- Thank you received: 0
4 years 10 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
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
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 29
- Thank you received: 0
4 years 10 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
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
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12925
- Thank you received: 3977
4 years 10 months ago #185431
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
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
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
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 29
- Thank you received: 0
4 years 10 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
enclosed you'll the questions as lsq-file.
Thank you,
Petteri
Attachments:
The topic has been locked.