- Posts: 11
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Maximum Sum drawn from previous answer
- Brimfulof
- Topic Author
- Offline
- New Member
Less
More
7 years 10 months ago #135400
by Brimfulof
Maximum Sum drawn from previous answer was created by Brimfulof
I originally posted this in the wrong category, so reposting in the right place, apologies for the duplication.
This seems like it should be obvious, but I couldn't find anyone else asking about it. This is what I'm trying to achieve:
Q1. How many people are participating? (answer is a numeral)
Q2. How many votes are cast for options:
a) (numerical input)
b) (numerical input)
c) (numerical input)
The total sum of votes cast in Q2 should be no higher than the answer to Q1 (it may be lower as some may not vote).
So in the advanced settings of Q2 I put "{Q1code}" in the Maximum sum value field.
This doesn't seem to work, as it won't let me give any answer to Q2 and the tip says:
if( ! is_empty('') && is_empty( { groups } ), sprintf('The sum must be at least %s', fixnum('')), '')if(is_empty('') && ! is_empty( { groups } ), sprintf('The sum must be at most %s', fixnum( { groups } )), '')if( ! is_empty('') && ('') == ( { groups } ), sprintf('The sum must equal %s', fixnum('')), '')if( ! is_empty('') && ! is_empty( { groups } ) && ('') != ( { groups } ), sprintf('The sum must be between %s and %s', fixnum(''), fixnum( { groups } )), '')
N.B. the code here for Q2 is 'groups'.
What am I getting wrong?
This seems like it should be obvious, but I couldn't find anyone else asking about it. This is what I'm trying to achieve:
Q1. How many people are participating? (answer is a numeral)
Q2. How many votes are cast for options:
a) (numerical input)
b) (numerical input)
c) (numerical input)
The total sum of votes cast in Q2 should be no higher than the answer to Q1 (it may be lower as some may not vote).
So in the advanced settings of Q2 I put "{Q1code}" in the Maximum sum value field.
This doesn't seem to work, as it won't let me give any answer to Q2 and the tip says:
if( ! is_empty('') && is_empty( { groups } ), sprintf('The sum must be at least %s', fixnum('')), '')if(is_empty('') && ! is_empty( { groups } ), sprintf('The sum must be at most %s', fixnum( { groups } )), '')if( ! is_empty('') && ('') == ( { groups } ), sprintf('The sum must equal %s', fixnum('')), '')if( ! is_empty('') && ! is_empty( { groups } ) && ('') != ( { groups } ), sprintf('The sum must be between %s and %s', fixnum(''), fixnum( { groups } )), '')
N.B. the code here for Q2 is 'groups'.
What am I getting wrong?
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
7 years 10 months ago #135422
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 Maximum Sum drawn from previous answer
Can you attache a small sample survey containing only those questions?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- Brimfulof
- Topic Author
- Offline
- New Member
Less
More
- Posts: 11
- Thank you received: 0
7 years 10 months ago #135467
by Brimfulof
Replied by Brimfulof on topic Maximum Sum drawn from previous answer
Hi,
I've created one here: involver.org.uk/ask/index.php/495238?lang=en
I attach the survey structure file:
Thanks for your help.
I've created one here: involver.org.uk/ask/index.php/495238?lang=en
I attach the survey structure file:
Thanks for your help.
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
7 years 10 months ago #135471
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 Maximum Sum drawn from previous answer
You can remove the "Maximum sum value" setting and use this for the "Question validation equation":
And, then something like this for the "Question validation tip":
Code:
sum(self.NAOK) <= Groups
And, then something like this for the "Question validation tip":
Code:
{if(sum(self.NAOK) > Groups, 'The total must be less than '+Groups+'!', 'Enter values up to a total of '+Groups+'.')}
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.
- Brimfulof
- Topic Author
- Offline
- New Member
Less
More
- Posts: 11
- Thank you received: 0
7 years 10 months ago #135487
by Brimfulof
Replied by Brimfulof on topic Maximum Sum drawn from previous answer
That's great.
All seems to work.
Thanks.
All seems to work.
Thanks.
The topic has been locked.