if condition in equation question

More
1 month 2 weeks ago #186334 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

Please Log in or Create an account to join the conversation.

LimeSurvey Partners
More
1 month 2 weeks ago #186335 by sugeek
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

Please Log in or Create an account to join the conversation.

More
1 month 2 weeks ago #186342 by Joffm
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

Please Log in or Create an account to join the conversation.

More
1 month 2 weeks ago #186366 by sugeek
Ey, thank you, is a great idea!!!

LimeSurvey Colombia Partner
www.sugeek.co

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!