How do I use constant sum to measure time use in a day? | XM Community
Skip to main content

I want to ask respondents how to spend their time in different categories of activities, and so I need 2 columns; one for hours and the other for minutes. However, I need it all to sum up to 24 hours. Ideally, column 1 would be hours, column 2 would be minutes, column 3 would be a total that is computed by (hours + (minutes/60)), and at the bottom of column 3, a total of all values in column 3 (all implemented in real-time).
I am unfamiliar with Javascript, if anyone could help that would be greatly appreciated.

Hi,
I do not believe the constant sum question type can have multiple columns. You could go with a Matrix question type and change the Matrix type to constant sum, but the sum would still be a total of hours and minutes.
You might consider using a side by side question type and having respondents do text entry to input a value in the Hours column and a value for the Minutes column. Then, if you would like the calculation of these 2 columns to display in a third column, Total, this would be accomplished via javascript. I don't have the exact code for this but in the below thread, rondev recommends using an 'input event on column text boxes which on every input calculate the sum of all rows of respective column through loop'
https://community.qualtrics.com/XMcommunity/discussion/19137/how-to-sum-side-by-side-answer-inputs-on-same-page-using-javascript
Then, to display a total of the Total column and on the same page, this would require jacascript as well. In the below thread, TomG provides some code around how this could be accomplished via an event handler:
https://community.qualtrics.com/XMcommunity/discussion/9743/display-math-operation-results-real-time
If not having the Totals display on the same page is okay, you could avoid javascript and collect the Hours and Minutes values via a side by side question type on 1 page, and then display the computation results on the following page using embedded fields and Math Operations. Then if you include these values as Default values for the question on page 2, you could include the 24 hours validation there.


Thanks Tom_1842, I've seen both these threads but as I am unfamiliar with Javascript, I'm not sure how to implement the first "input event" although that sounds like exactly what I would need.


Leave a Reply