# Add Two Continuous Sums into a Third

While there is no built-in functionality to populate a continuous sum question with previous continuous sum questions we have a script to accomplish this! This can come in handy if you have different totals that you want to add to make one overall total. These steps assume a basic familiarity with SurveyGizmo and Custom Scripting.

Check it out in an example survey

OR

### Setup

Features and functions used in this script:

Start by building all of your survey questions. In this example survey, we have both continuous sum questions that will be doing the addition on the first page.

On the next page, we have a custom script action with the below script followed by two hidden values. These hidden values will be populated by the script.

You will need to change the IDs for the continuous sum questions and hidden values.

``````
contsum1 = 7 --Question ID for first Continuous Sum
contsum2 = 8 --Question ID for second Continuous Sum
sum1 = 5 -- ID of hidden value for first sum
sum2 = 6 -- ID of hidden value for second sum
next_pageID = 3 --ID of page to jump to so page with script does not show.

array = getvalue(contsum1)
chars = {'%','\$','₠','₡','₢','₣','₤','₥','₦','₧','₨','₩','₪','₫','€','₭','₮','₯','₱','₲','₳','₴','₵','₶','₷','₸','₹'}

finalval=0

for key,value in pairs (array) do

val = str_replace(chars, '', value)
val = tonumber(val)
finalval = finalval+val

end

setvalue(sum1,finalval)

array2 = getvalue(contsum2)

finalval2 = 0

for key2,value2 in pairs (array2) do

val2 = str_replace(chars, '', value2);
val2 = tonumber(val2)
finalval2 = finalval2+val2

end

setvalue(sum2,finalval2)

jumptopage(next_pageID)
``````

Now on the third page, add the third Continuous Sum question where you wish to add all the values together. Populate the Default Value field for each option with the merge code for the Hidden Value sums we populated in the script.

Now you're ready to test your survey. Is your third continuous sum populating with the totals of the first two creating and total sum? If so, you've succeeded! Congratulations! If not, double check your question IDs.

### Scripting and Other Custom Solutions

We’re always happy to help you debug any documented script that is used as is. That said, we do not have the resources to write scripts on demand or to debug a customized script.

If you have customization ideas that you haven't figured out how to tackle, we're happy to be a sounding board for SurveyGizmo features and functionality ideas that might meet your needs. Beyond this, check out our Professional Services; these folks have the scripting chops to help you to achieve what you are looking for!

Basic Standard Market Research HR Professional Full Access Reporting
Free Individual Team & Enterprise
Feature Included In