Welcome to the LimeSurvey Community Forum

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

equation question - syntax issue

  • marektondryk
  • marektondryk's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
5 years 6 months ago #173411 by marektondryk
equation question - syntax issue was created by marektondryk


I have 3 questions (q1, q2, q3) radio list each one with answers 'yes' (A1) and 'no' (A2).
I want answer returned from equation question for condition:
{if answer for q1=A2 and answer for q2=A2 and answer for q3=A2 than "red" or
if answer for q1=A1 and answer for q2=A2 and answer for q3=A2 than "green" or
if answer for q1=A1 and answer for q2=A1 and answer for q3=A2 than "blue" or
if answer for q1=A1 and answer for q2=A1 and answer for q3=A1 than "yellow"}

How should this equation question look like?
Attachments:
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 6 months ago - 5 years 6 months ago #173415 by DenisChenu
Replied by DenisChenu on topic equation question - syntax issue
I do :
Code:
{join(
if(q1=="A2" and q2=="A2" and q3=="A2",'red',''),
if(q1=="A1" and q2=="A2" and q3=="A2",'green',''),
if(q1=="A1" and q2=="A1" and q3=="A2",'blue',''),
if(q1=="A1" and q2=="A1" and q3=="A1",'yellow',''),
'')}
Because it's more simple to understand and fix then imbricated if : manual.limesurvey.org/Expression_Manager...Conditional_Logic.29

(corrected)

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: 5 years 6 months ago by DenisChenu. Reason: Use == not = silly boy
The following user(s) said Thank You: marektondryk
The topic has been locked.
More
5 years 6 months ago #173418 by jelo
Replied by jelo on topic equation question - syntax issue

However, we recommend using the join() function for concatenation, as that makes your intent more clear, and avoids unexpected results if you were expecting strings but got numbers instead (or vice versa).

manual.limesurvey.org/Expression_Manager#Operators

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The following user(s) said Thank You: marektondryk
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 6 months ago #173421 by tpartner
Replied by tpartner on topic equation question - syntax issue
Why the join function? Since they are mutually exclusive, why not simply use four IF() statements (not nested)?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: marektondryk
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 6 months ago - 5 years 6 months ago #173422 by DenisChenu
Replied by DenisChenu on topic equation question - syntax issue

tpartner wrote: Why the join function? Since they are mutually exclusive, why not simply use four IF() statements (not nested)?

Maybe in future Equation question type save line feed ;).

But currently : you're right, can be done with
Code:
{if(q1=="A2" and q2=="A2" and q3=="A2",'red','')}
{if(q1=="A1" and q2=="A2" and q3=="A2",'green','')}
{if(q1=="A1" and q2=="A1" and q3=="A2",'blue','')}
{if(q1=="A1" and q2=="A1" and q3=="A1",'yellow','')}

(Edited/corrected)

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: 5 years 6 months ago by DenisChenu. Reason: Use == not = silly boy !
The following user(s) said Thank You: marektondryk
The topic has been locked.
  • marektondryk
  • marektondryk's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
5 years 6 months ago #173446 by marektondryk
Replied by marektondryk on topic equation question - syntax issue
Thanks guys :)
I put code:
{if(q1="A2" and q2="A2" and q3="A2",'red','')}
{if(q1="A1" and q2="A2" and q3="A2",'green','')}
{if(q1="A1" and q2="A1" and q3="A2",'blue','')}
{if(q1="A1" and q2="A1" and q3="A1",'yellow','')}

into new equation question and I don't get yellow,blue, etc. answer...
What should I do???? :(
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 6 months ago #173448 by holch
Replied by holch on topic equation question - syntax issue
Send a LSS file with what you have done.

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.
  • marektondryk
  • marektondryk's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
5 years 6 months ago #173455 by marektondryk
Replied by marektondryk on topic equation question - syntax issue

File Attachment:

File Name: test.lss
File Size:16 KB
Attachments:
The topic has been locked.
More
5 years 6 months ago - 5 years 6 months ago #173457 by vkuzmin
Replied by vkuzmin on topic equation question - syntax issue
Use dual equality == to compare values
[strike]UPD: And use quotes instead of apostrophes.[/strike]
Last edit: 5 years 6 months ago by vkuzmin.
The following user(s) said Thank You: marektondryk
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 6 months ago #173471 by tpartner
Replied by tpartner on topic equation question - syntax issue

Use dual equality == to compare values

Duh...that's a rookie mistake, not catching that :)

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: marektondryk
The topic has been locked.
  • marektondryk
  • marektondryk's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
5 years 6 months ago #173479 by marektondryk
Replied by marektondryk on topic equation question - syntax issue
Thanks!!!!! :) Works GREAT!!!
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 6 months ago #173482 by DenisChenu
Replied by DenisChenu on topic equation question - syntax issue

tpartner wrote:

Use dual equality == to compare values

Duh...that's a rookie mistake, not catching that :)

Arg … my mistake … :S

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.

Lime-years ahead

Online-surveys for every purse and purpose