- Posts: 61
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Sum & validation in multiple numerical input question
- vzyldd
- Topic Author
- Offline
- Senior Member
Less
More
5 years 6 months ago #173247
by vzyldd
Sum & validation in multiple numerical input question was created by vzyldd
Hi, need a little guidance please.
I'm using a multiple numerical input question but needs to validate the totals of the different sub-questions individually.
I need to check that the answer in sub-question 1 equals the sum of sub-question 2 and 3. Check that sub-question 4 is not more than the answer in sub-question 1.
I tried the validation in the sub-question validation box but somewhere I'm missing the target. I've used the following:
sum(Q2_4)=<sum(Q2_1) but are not sure if I am on the right track.
I'm using a multiple numerical input question but needs to validate the totals of the different sub-questions individually.
I need to check that the answer in sub-question 1 equals the sum of sub-question 2 and 3. Check that sub-question 4 is not more than the answer in sub-question 1.
I tried the validation in the sub-question validation box but somewhere I'm missing the target. I've used the following:
sum(Q2_4)=<sum(Q2_1) but are not sure if I am on the right track.
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
5 years 6 months ago #173255
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Sum & validation in multiple numerical input question
I would think the question validation equation would be something like:
Code:
{Q2_1 == sum(Q2_2, Q2_3) && Q2_4 <= Q2_1}
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: vzyldd
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12790
- Thank you received: 3940
5 years 6 months ago - 5 years 6 months ago #173257
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Sum & validation in multiple numerical input question
Hi,
yes, you are.
So it is something like:
(Q2_1==sum(Q2_2,Q2_3) AND (Q2_1>=Q2_4)
And the tip could be:
{if(Q2_1!=sum(Q2_2,Q2_3),"Sum not equal Total","")}
...
But you have to add something that allows empty fields. Otherwise you will see the red border if "Total" is filled, but "boys" and "girls" still empty. Of course the sum is not equal in this case.
Best regards
Joffm
yes, you are.
But why do you "sum"? This are single fields.sum(Q2_4)=<sum(Q2_1)
So it is something like:
(Q2_1==sum(Q2_2,Q2_3) AND (Q2_1>=Q2_4)
And the tip could be:
{if(Q2_1!=sum(Q2_2,Q2_3),"Sum not equal Total","")}
...
But you have to add something that allows empty fields. Otherwise you will see the red border if "Total" is filled, but "boys" and "girls" still empty. Of course the sum is not equal in this case.
Best regards
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
Last edit: 5 years 6 months ago by Joffm.
The following user(s) said Thank You: vzyldd
The topic has been locked.
- l1bxr02
- Offline
- New Member
Less
More
- Posts: 7
- Thank you received: 0
4 years 8 months ago #186706
by l1bxr02
Replied by l1bxr02 on topic Sum & validation in multiple numerical input question
Hello there
This is what I am trying to do.
4.A.(1)
(2)
4.B. (1)
(2)
(3)
4.C. Sum of 4.A(1) through 4.B(3)
Is this equation correct? Am I missing something?
{4.C = sum(4.A.(1), 4.A.(2)) AND sum(4.B.(1),4.B.(2),4.B.(3)}
This is what I am trying to do.
4.A.(1)
(2)
4.B. (1)
(2)
(3)
4.C. Sum of 4.A(1) through 4.B(3)
Is this equation correct? Am I missing something?
{4.C = sum(4.A.(1), 4.A.(2)) AND sum(4.B.(1),4.B.(2),4.B.(3)}
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12790
- Thank you received: 3940
4 years 8 months ago #186711
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Sum & validation in multiple numerical input question
Now you ask the same question in three really outdated posts.
Would be better you open a new post with an attached sample of your survey (*.lss) with the relevant questions.
I assume 4A and 4B are two questions of type multiple numerical input.
And if you'd read the manual here
manual.limesurvey.org/Expression_Manager...code_variable_naming
and
manual.limesurvey.org/Expression_Manager....22that.22_variables
Having read this
you know that your equation has to look like this:
{sum(QuestionCode_SubQuestionCode1,QuestionCode_SubQuestionCode2,QuestionCode_SubQuestionCode3,...)}
If you can use the "that"-variable you can shorten to
{sum(that.QuestionCode)}
Joffm
Would be better you open a new post with an attached sample of your survey (*.lss) with the relevant questions.
I assume 4A and 4B are two questions of type multiple numerical input.
And if you'd read the manual here
manual.limesurvey.org/Expression_Manager...code_variable_naming
and
manual.limesurvey.org/Expression_Manager....22that.22_variables
Having read this
"Here are the details of how to construct a Qcode (and access some properties) by question type. In general, Qcodes are constructed as:
QuestionCode . '_' . SubQuestionID . '_' . ScaleId"
you know that your equation has to look like this:
{sum(QuestionCode_SubQuestionCode1,QuestionCode_SubQuestionCode2,QuestionCode_SubQuestionCode3,...)}
If you can use the "that"-variable you can shorten to
{sum(that.QuestionCode)}
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu
The topic has been locked.