Welcome to the LimeSurvey Community Forum

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

Maximum Sum drawn from previous answer

  • Brimfulof
  • Brimfulof's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 6 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?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 6 months ago #135422 by tpartner
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
  • Brimfulof's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 6 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:

File Attachment:

File Name: limesurvey...5238.lss
File Size:15 KB

Thanks for your help.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 6 months ago #135471 by tpartner
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":

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+'.')}


File Attachment:

File Name: limesurvey...8_TP.lss
File Size:16 KB

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
  • Brimfulof's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 6 months ago #135487 by Brimfulof
Replied by Brimfulof on topic Maximum Sum drawn from previous answer
That's great.

All seems to work.

Thanks.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose