Welcome to the LimeSurvey Community Forum

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

if condition in equation question

  • sugeek
  • sugeek's Avatar Topic Author
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
4 years 9 months ago #186334 by sugeek
if condition in equation question was created by sugeek
Hi every body, we will create a question that calculate a result based in 2 question. We have this structure with 'if' condition:

{if(!is_empty(G2Q00001_SQ001.NAOK && G2Q00001_SQ002.NAOK && G2Q00001_SQ003.NAOK),
if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A1' && G2Q00002_SQ003=='A1',0.8 + 0.95 + 0.95,
if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A1' && G2Q00002_SQ003=='A2',0.8 + 0.95,
if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A2' && G2Q00002_SQ003=='A1',0.8 + 0.95,
if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A2' && G2Q00002_SQ003=='A2',0.8,
if(G2Q00002_SQ001=='A2' && G2Q00002_SQ002=='A1' && G2Q00002_SQ003=='A1',0.95 + 0.95,
if(G2Q00002_SQ001=='A2' && G2Q00002_SQ002=='A1' && G2Q00002_SQ003=='A2',0.95,
if(G2Q00002_SQ001=='A2' && G2Q00002_SQ002=='A2' && G2Q00002_SQ003=='A1',0.95,0)))))),

if(!is_empty(G2Q00001_SQ001.NAOK && G2Q00001_SQ002.NAOK),
if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A1',1.56 + 1.78,
if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A2',1.56,
if(G2Q00002_SQ001=='A2' && G2Q00002_SQ002=='A1',1.56,0))),


if(!is_empty(G2Q00001_SQ001.NAOK && G2Q00001_SQ003.NAOK),
if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A1',1.56 + 1.78,
if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A2',1.56,
if(G2Q00002_SQ001=='A2' && G2Q00002_SQ002=='A1',1.56,0))),

if(!is_empty(G2Q00001_SQ001.NAOK),
if(G2Q00002_SQ001=='A1',6.25,0)

))))}


We have a little error, when we mark all subquestion (first 'if' condition), the result is true and go to 'if' conditions into true result, but, when the result is false, the other if not work.

¿What is our error?.

Thanks,

LimeSurvey Colombia Partner
www.sugeek.co
The topic has been locked.
  • sugeek
  • sugeek's Avatar Topic Author
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
4 years 9 months ago #186335 by sugeek
Replied by sugeek on topic if condition in equation question
Have a solution:
{if(G2Q00001_SQ001.NAOK=='Y' && G2Q00001_SQ002.NAOK=='Y' && G2Q00001_SQ003.NAOK=='Y',

(if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A1' && G2Q00002_SQ003=='A1',0.8 + 0.95 + 0.95,
if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A1' && G2Q00002_SQ003=='A2',0.8 + 0.95,
if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A2' && G2Q00002_SQ003=='A1',0.8 + 0.95,
if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A2' && G2Q00002_SQ003=='A2',0.8,
if(G2Q00002_SQ001=='A2' && G2Q00002_SQ002=='A1' && G2Q00002_SQ003=='A1',0.95 + 0.95,
if(G2Q00002_SQ001=='A2' && G2Q00002_SQ002=='A1' && G2Q00002_SQ003=='A2',0.95,
if(G2Q00002_SQ001=='A2' && G2Q00002_SQ002=='A2' && G2Q00002_SQ003=='A1',0.95,0)))))))),'')}

{if(G2Q00001_SQ001.NAOK=='Y' && G2Q00001_SQ002.NAOK=='Y' && G2Q00001_SQ003.NAOK!='Y',

(if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A1',1.56 + 1.78,
if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A2',1.56,
if(G2Q00002_SQ001=='A2' && G2Q00002_SQ002=='A1',1.56,0)))),'')}

{if(G2Q00001_SQ001.NAOK=='Y' && G2Q00001_SQ003.NAOK=='Y' && G2Q00001_SQ002.NAOK!='Y',

(if(G2Q00002_SQ001=='A1' && G2Q00002_SQ003=='A1',1.56 + 1.78,
if(G2Q00002_SQ001=='A1' && G2Q00002_SQ003=='A2',1.56,
if(G2Q00002_SQ001=='A2' && G2Q00002_SQ003=='A1',1.56,0)))),'')}

{if(G2Q00001_SQ001.NAOK=='Y' && G2Q00001_SQ002.NAOK!='Y' && G2Q00001_SQ003.NAOK!='Y',
(if(G2Q00002_SQ001=='A1',6.25,0)),'')}

LimeSurvey Colombia Partner
www.sugeek.co
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 9 months ago #186342 by Joffm
Replied by Joffm on topic if condition in equation question
Hi,

{if(G2Q00001_SQ001.NAOK=='Y' && G2Q00001_SQ002.NAOK=='Y' && G2Q00001_SQ003.NAOK=='Y',

(if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A1' && G2Q00002_SQ003=='A1',0.8 + 0.95 + 0.95,
if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A1' && G2Q00002_SQ003=='A2',0.8 + 0.95,
if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A2' && G2Q00002_SQ003=='A1',0.8 + 0.95,
if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A2' && G2Q00002_SQ003=='A2',0.8,
if(G2Q00002_SQ001=='A2' && G2Q00002_SQ002=='A1' && G2Q00002_SQ003=='A1',0.95 + 0.95,
if(G2Q00002_SQ001=='A2' && G2Q00002_SQ002=='A1' && G2Q00002_SQ003=='A2',0.95,
if(G2Q00002_SQ001=='A2' && G2Q00002_SQ002=='A2' && G2Q00002_SQ003=='A1',0.95,0)))))))),'')}


supposing that
G2Q00002_SQ001=='A1' adds 0.8,
G2Q00002_SQ002=='A1' adds 0.95,
G2Q00002_SQ003=='A1' adds 0.95

you can shorten to
{if(G2Q00001_SQ001.NAOK=='Y' && G2Q00001_SQ002.NAOK=='Y' && G2Q00001_SQ003.NAOK=='Y',
sum(if(G2Q00002_SQ001=='A1',0.8,0),if(G2Q00002_SQ002=='A1',0.95,0),if(G2Q00002_SQ003=='A1',0.95,0)),"")}


So maybe you can shorten the other equations in the same way.

{if(G2Q00001_SQ001.NAOK=='Y' && G2Q00001_SQ002.NAOK=='Y' && G2Q00001_SQ003.NAOK!='Y',

(if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A1',1.56 + 1.78,
if(G2Q00002_SQ001=='A1' && G2Q00002_SQ002=='A2',1.56,
if(G2Q00002_SQ001=='A2' && G2Q00002_SQ002=='A1',1.56,0)))),'')}


And here I should have thought that
G2Q00002_SQ001=='A1' adds 1.56,
G2Q00002_SQ002=='A1' adds 1.78
But then the third line should be
if(G2Q00002_SQ001=='A2' && G2Q00002_SQ002=='A1',1.78,0)))),'')}

Of course I have not the least idea of your calculation and so I do not know if it is a typo.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: cdorin
The topic has been locked.
  • sugeek
  • sugeek's Avatar Topic Author
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
4 years 9 months ago #186366 by sugeek
Replied by sugeek on topic if condition in equation question
Ey, thank you, is a great idea!!!

LimeSurvey Colombia Partner
www.sugeek.co
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose