I have a survey with 16 questions. Each question is the Singel Select type with 2 or 3 answers. Each answer is given a score of either 0, 5, 10, or 15 points. What I want to do is set it up so that the points are added up and automatically populate a Home Assessment Score field with the sum of the points (somewhere between 0 and 130 points). I also want it to automatically select the Home Assessment Rating field rating (0-25 = Low Risk Hazard, 26-50 = Medium Risk, 51-100 = High Risk, and > 100 = Extreme Risk.
Any suggestions would be appreciated, thanks!
Link to Survey here.
Question example:
What is the value being stored when those options are selected? Is it storing the actual numeric value for the score?
It would be tedious to write out, but would be as simple as $question_1 + $question_2 + $question_3 in the calculation column of your assessment score field.
If the questions have some value other than the numeric score, you'd need your expression to decode the values first, then add them up, which is likely to be even more tedious.
Personally, I'd suggest using a custom JavaScript function to handle this, as that can be much easier to work with and debug than a long calculation expression.
At this point (I built this via the Survey123 web tool) the value being stored is the answer selected. See the example I posted the screenshot of. I am not that familiar with customization of the table via Survey123 Connect. Like, is there a way to associate the needed points for each possible response and then create a script like you suggest selecting the number selected?
I am wondering if another way of approaching this would be set up a numerical answer to the question rather than radio buttons to select the answer?
Switching to numeric values would be much simpler. But to answer your question, it would be simple enough to have an object in JS in which the answer and its point value act as a key/value pair.
var q_points = {
"First Answer": 5,
"Second Answer": 10,
"Third Answer": 0,
"First Answer but to a different question": 5,
"and so on": 10
}
And then you could use the value of the question to pull the points. Assuming you included your answers on the JS function as parameters like "q1", "q2", etc, it might look like this:
var the_sum = q_points[q1] + q_points[q2] + ...
return the_sum
Interesting. I will play around with this and see what happens. There is a bit of a learning curve happening here as I have never worked on the spreadsheet side of things via Survey Connect. Thanks for the suggestions.
Just an FYI JS is not supported for public surveys so if you plan on making your survey accessible to everyone you will need to do your calculations in the calculation column of your survey.
Ah, good to know. I knew there was a reason why I have always avoided building surveys via Survey123 connect.....
Connect works with all surveys, it is specifically using a JavaScript function that doesn't work in public surveys.
Thanks Jennifer, that is what I thought you meant.