1 year 3 months ago - 1 year 3 months ago #156822 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

1.
2.
3.

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: 1 year 3 months ago by Sweden.

1 year 3 months ago - 1 year 3 months ago #156824
1st remind : = is assign, and == is test.

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

is (in a equation question type)
```{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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Last Edit: 1 year 3 months ago by DenisChenu.
The following user(s) said Thank You: Sweden

1 year 3 months ago #156825 by Sweden
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).

1 year 3 months ago #156827
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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .