# equation to test coherence between two answers (array with subquestion)

1 year 2 months ago #160430
lefebvremarianne created the topic: equation to test coherence between two answers (array with subquestion)
Hello

I need to check whether the answers to Qu1 is coherent with the answer in Qu7. It is coherent if is the opposite (A in Qu1 and B in Qu7 or B in Qu1 and A in Qu7 ).
The questions 1 and 7 are of array type, with one subquestion (choice between "Option AX" and "Option BX", with X=1 or 7).

To do so, I have set-up a question of type "equation" in the group of questions where I have question 7.
Given that I have 8 versions of the questionnaire (8 blocks), I have 16 conditions in my equation.
I want the response to this question to be 1 if the answers are coherent and 0 otherwise.

My problem: When I answer to the questionnaire, I don't see any value in the column corresponding to this coherence question. Can you see an error in the equation?

{if(Block1Qu1[SQ001]=='Option A1' and Block1Qu7[SQ001]=='Option B7', 1,
if(Block2Qu1[SQ001]=='Option A1' and Block2Qu7[SQ001]=='Option B7', 1,
if(Block3Qu1[SQ001]=='Option A1' and Block3Qu7[SQ001]=='Option B7', 1,
if(Block4Qu1[SQ001]=='Option A1' and Block4Qu7[SQ001]=='Option B7', 1,
if(Block5Qu1[SQ001]=='Option A1' and Block5Qu7[SQ001]=='Option B7', 1,
if(Block6Qu1[SQ001]=='Option A1' and Block6Qu7[SQ001]=='Option B7', 1,
if(Block7Qu1[SQ001]=='Option A1' and Block7Qu7[SQ001]=='Option B7', 1,
if(Block8Qu1[SQ001]=='Option A1' and Block8Qu7[SQ001]=='Option B7', 1,
if(Block1Qu1[SQ001]=='Option B1' and Block1Qu7[SQ001]=='Option A7', 1,
if(Block2Qu1[SQ001]=='Option B1' and Block2Qu7[SQ001]=='Option A7', 1,
if(Block3Qu1[SQ001]=='Option B1' and Block3Qu7[SQ001]=='Option A7', 1,
if(Block4Qu1[SQ001]=='Option B1' and Block4Qu7[SQ001]=='Option A7', 1,
if(Block5Qu1[SQ001]=='Option B1' and Block5Qu7[SQ001]=='Option A7', 1,
if(Block6Qu1[SQ001]=='Option B1' and Block6Qu7[SQ001]=='Option A7', 1,
if(Block7Qu1[SQ001]=='Option B1' and Block7Qu7[SQ001]=='Option A7', 1,
if(Block8Qu1[SQ001]=='Option B1' and Block8Qu7[SQ001]=='Option A7', 1, 0
))))))))))))))))}

1 year 2 months ago #160431
DenisChenu replied the topic: equation to test coherence between two answers (array with subquestion)
Hi,

1. error in variable name : Block1Qu1[SQ001] to Block1Qu1_SQ001, see manual.limesurvey.org/Expression_Manager#Qcode_Variable_Naming
2. It's better to use answer code 'Option B1' to "B1" if code is B1

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 .
The following user(s) said Thank You: lefebvremarianne

1 year 2 months ago #160438
lefebvremarianne replied the topic: equation to test coherence between two answers (array with subquestion)
Thanks a lot. Its working!