Constant Sum Must Total but not mandatory? | XM Community
Skip to main content
Is it possible to custom code a constant sum question so that the responses must total 100%, but it could also be left blank (all rows at 0) as well?
Yes, sum the total anytime one of the fields changes, then enable the next button if it totals 0 or 100, otherwise disable the next button.
Hello @Nadaly



The solution is using custom validation.



In the Constant Sum question add following custom validation

!



In the first condition paste the following math operation

`$e{ 100 - ( q://QID24/ChoiceNumericEntryValue/2 + q://QID24/ChoiceNumericEntryValue/3 ) }`



In second condition(after OR) paste the following math operation

` $e{ 0 - ( q://QID24/ChoiceNumericEntryValue/2 + q://QID24/ChoiceNumericEntryValue/3 ) }`



Also, Select "Enforce Range" with 0 as min value, so that the user cannot answer negative values



Explanation: Suppose you have three rows(A, B, C) then either A= 100-(B+C) OR A=0- (B+C)
@Shashi Thanks. This makes sense. I got it to work using a 2-row question! But it doesn't on one that is 4 rows. Is this bad math?



$e{ 100 - ( q://QID7/ChoiceNumericEntryValue/2 + q://QID7/ChoiceNumericEntryValue/3 + q://QID7/ChoiceNumericEntryValue/4) }



$e{ 0 - ( q://QID7/ChoiceNumericEntryValue/2 + q://QID7/ChoiceNumericEntryValue/3 + q://QID7/ChoiceNumericEntryValue/4) }
> @Nadaly said:

> @Shashi Thanks. This makes sense. I got it to work using a 2-row question! But it doesn't on one that is 4 rows. Is this bad math?

>

> $e{ 100 - ( q://QID7/ChoiceNumericEntryValue/2 + q://QID7/ChoiceNumericEntryValue/3 + q://QID7/ChoiceNumericEntryValue/4) }

>

> $e{ 0 - ( q://QID7/ChoiceNumericEntryValue/2 + q://QID7/ChoiceNumericEntryValue/3 + q://QID7/ChoiceNumericEntryValue/4) }



There should be a space between 4 and ')'
Hi, I have exactly the same problem but for me the code provided above does not seem to work.

I am using:

$e{ 100 - ( q://QID206/ChoiceNumericEntryValue/2 + q://QID206/ChoiceNumericEntryValue/3 + q://QID206/ChoiceNumericEntryValue/4 + q://QID206/ChoiceNumericEntryValue/5 ) }



and my question looks like this:!
@_Hannah1073

I tried your code on a slider question and it worked fine for me to prevent someone from moving forward unless the sum was 100. What is happening for you? Are respondents able to move forward with a sum>100?

Leave a Reply