Creating a tally from a checklist

Hi, Does anyone know how to create a score from a checklist? We have a question which asks households to select which assets they have in their home? There are 7 items on the list and each has a different value. i.e. a tractor is 5 points whereas a diesel pump is just 2 points. We want to add up the points to create an 'asset score' for that family. The question is set up as a checklist. I have created a hidden value for each of the answers (assets) using an if statement. i.e. if tractor is selected, then 5, if not 0 etc. I then have another hidden value which sums all the hidden values. It works when only one asset is selected. But when more than one asset is selected, it returns 0. i.e. if the household has a tractor and a diesel pump, it should return 7. What am I doing wrong? I assuming its something in the if statements with checklists? Thanks for any help. Ive looked at the pages on checklists, weighted checklists (this doesnt work as i want a score not a true or false value), tally scores etc but still cant work it out!

thanks Nicola

Hi Nicola,

It sounds like you are trying to ask a multiple choice question where each potential choice comes with a point value, and you want to sum up the point values of each selected choice?

I think there are two ways to achieve that.

One would be to manually add up each potential selection with the point value assigned in the question within the total.

This would look like a hidden value total with a calculation like

if( selected(#form/options, 'value_one'), 5, 0 ) + if( selected(#form/options, 'value_two'), 2, 0 ) + ....

If this is a pattern you are applying quite broadly and will need to re-use the same addition logic, you could also use a lookup table to encode things a bit more all-in-one-place.

If your lookup table had a column with a unique choice_id (like value_one) and another column with a choice_score (like 4) I believe you could use the sum() function to iterate over each item in the table and see if it was selected within the lookup table question, like

sum(instance('item-list:choice')/choice_list/choice[selected(#form/options, choice_id)]/choice_score)

This would sum up the choice score for each row in the lookup table which has a choice id which is present in the user's entered value for the question. I don't quite remember how it would handle no selection, though, so you might need to special case that.

Hi Clayton, thanks for this. very helpful! All working now. thanks Nicola