- Posts: 59
- Thank you received: 3
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Equation - how can I assign individual ID's for different answer combinations?
- Sweden
- Topic Author
- Offline
- Senior Member
Less
More
6 years 9 months ago - 6 years 9 months ago #156822
by Sweden
Equation - how can I assign individual ID's for different answer combinations? was created by Sweden
Lets say that I have the following questions in my survey:
Multiple Choice (Question code: Q1)
1.
2.
3.
Yes/No (Question code: Q2)
Yes
No
Radio list (Question code: Q3)
1.
2.
3.
I want to assign individual ID's for different answer combinations e.g.:
IF Q1=2 AND Q2="Yes" AND Q3=1 THEN ID = 100
IF Q1=1 AND Q2="No" AND Q3=2 THEN ID = 200
IF Q1=1 AND Q2="Yes" AND Q3=3 THEN ID = 300
I have tried to use the question type "Equation" for this (would prefer this instead of javascript), but I just can't figure out how it works. I have looked in the manual etc. but I haven't found any good examples for my situation. Could someone please help me with the equation for the example above where questions codes are used (e.g. Q1_SQ002). One equation should be able to handle all three mentioned answer combinations. That means that the value stored in the database should be 100, 200 or 300 (or empty depending on the combination of answers).
Multiple Choice (Question code: Q1)
1.
2.
3.
Yes/No (Question code: Q2)
Yes
No
Radio list (Question code: Q3)
1.
2.
3.
I want to assign individual ID's for different answer combinations e.g.:
IF Q1=2 AND Q2="Yes" AND Q3=1 THEN ID = 100
IF Q1=1 AND Q2="No" AND Q3=2 THEN ID = 200
IF Q1=1 AND Q2="Yes" AND Q3=3 THEN ID = 300
I have tried to use the question type "Equation" for this (would prefer this instead of javascript), but I just can't figure out how it works. I have looked in the manual etc. but I haven't found any good examples for my situation. Could someone please help me with the equation for the example above where questions codes are used (e.g. Q1_SQ002). One equation should be able to handle all three mentioned answer combinations. That means that the value stored in the database should be 100, 200 or 300 (or empty depending on the combination of answers).
Last edit: 6 years 9 months ago by Sweden.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13643
- Thank you received: 2491
6 years 9 months ago - 6 years 9 months ago #156824
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 Equation - how can I assign individual ID's for different answer combinations?
1st remind : = is assign, and == is test.
is (in a equation question type)IF Q1=2 AND Q2="Yes" AND Q3=1 THEN ID = 100
IF Q1=1 AND Q2="No" AND Q3=2 THEN ID = 200
IF Q1=1 AND Q2="Yes" AND Q3=3 THEN ID = 300
Code:
{ID=if(Q1==2 and Q2=="Yes" and Q3==1,100, if(Q1==1 and Q2=="No" and Q3==2,200, if(Q1==1 and Q2=="Yes" and Q3==3,300,"") ) )}
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.
Last edit: 6 years 9 months ago by DenisChenu.
The following user(s) said Thank You: Sweden
The topic has been locked.
- Sweden
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 59
- Thank you received: 3
6 years 9 months ago #156825
by Sweden
Replied by Sweden on topic Equation - how can I assign individual ID's for different answer combinations?
Thanks! Your code worked after I changed a few things (for those who don't know - multiple choise and radio list don't use the value 1,2,3 etc. Instead use SQ001="Y", SQ002="N" etc. for multiple choise questions and ="A1", ="A2" etc. for radio list questions).
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13643
- Thank you received: 2491
6 years 9 months ago #156827
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 Equation - how can I assign individual ID's for different answer combinations?
I just tranlate yor equation I Expression Manager
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.