Count of multiple select options within a repeat group

I have a multiple select/checkbox question with a repeat group, and I need
to do a count of how many times each option was selected.

The formula *count(/data/repeat[question_id = answer_1]) *works for
multiple choice questions or if only one option is selected on the multiple
select, but if 2+ options are selected, the logic fails. I know that
normally the syntax for multiple select questions is selected(#form/checkbox_questionid,
‘select_item_name’)
so I tried just adding *count() *around this, but then
I get an error message saying ‘this is not a nodeset’.

So basically–how do I combine the count function with the selected
function?

Thanks in advance!

Hi Jenn,

You need to put the selected() inside the [ ] still. So it would be:

count(/data/repeat[selected(question_id,“option_a”)])

You’d might need to convert the result of the selected to a 1 or 0, I’m not
positive, by doing the following:

sum(/data/repeat[if(selected(question_id, “select_item_name”),1,0)])

Note I switched to “sum” and not “count” also. I’m not sure which will
work, so give them each a try and let me know if it doesn’t do what you
need.

-Nick

Nick Nestle
Technical Project Manager | Dimagi Inc.

··· On Thu, Jun 22, 2017 at 11:18 AM, Jenn Masters Snyder < masters.jenn@gmail.com> wrote:

I have a multiple select/checkbox question with a repeat group, and I need
to do a count of how many times each option was selected.

The formula *count(/data/repeat[question_id = answer_1]) *works for
multiple choice questions or if only one option is selected on the multiple
select, but if 2+ options are selected, the logic fails. I know that
normally the syntax for multiple select questions is selected(#form/checkbox_questionid,
‘select_item_name’)
so I tried just adding *count() *around this, but
then I get an error message saying ‘this is not a nodeset’.

So basically–how do I combine the count function with the selected
function?

Thanks in advance!


You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi Jenn,

I believe the syntax you are looking for here would involve shifting the
"selected" syntax into the filter, rather than outside of it, so it would
look something like

count(/data/repeat[selected(./question_id, ‘select_item_name’)])

-Clayton

··· On Thu, Jun 22, 2017 at 2:18 PM, Jenn Masters Snyder <masters.jenn@gmail.com wrote:

I have a multiple select/checkbox question with a repeat group, and I need
to do a count of how many times each option was selected.

The formula *count(/data/repeat[question_id = answer_1]) *works for
multiple choice questions or if only one option is selected on the multiple
select, but if 2+ options are selected, the logic fails. I know that
normally the syntax for multiple select questions is selected(#form/checkbox_questionid,
‘select_item_name’)
so I tried just adding *count() *around this, but
then I get an error message saying ‘this is not a nodeset’.

So basically–how do I combine the count function with the selected
function?

Thanks in advance!


You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Clayton and Nick,
count(/data/repeat[selected(question_id,“option_a”)]) did the trick.
Thanks for your quick responses!

··· On Thursday, June 22, 2017 at 4:34:03 PM UTC-4, Nick Nestle wrote: > > Hi Jenn, > > You need to put the selected() inside the [ ] still. So it would be: > > count(/data/repeat[selected(question_id,"option_a")]) > > You'd might need to convert the result of the selected to a 1 or 0, I'm > not positive, by doing the following: > > sum(/data/repeat[if(selected(question_id, "select_item_name"),1,0)]) > > Note I switched to "sum" and not "count" also. I'm not sure which will > work, so give them each a try and let me know if it doesn't do what you > need. > > -Nick > > > > Nick Nestle > Technical Project Manager | Dimagi Inc. > > > > On Thu, Jun 22, 2017 at 11:18 AM, Jenn Masters Snyder <master...@gmail.com > wrote: > >> I have a multiple select/checkbox question with a repeat group, and I >> need to do a count of how many times each option was selected. >> >> The formula *count(/data/repeat[question_id = answer_1]) *works for >> multiple choice questions or if only one option is selected on the multiple >> select, but if 2+ options are selected, the logic fails. I know that >> normally the syntax for multiple select questions is *selected(#form/checkbox_questionid, >> 'select_item_name')* so I tried just adding *count() *around this, but >> then I get an error message saying 'this is not a nodeset'. >> >> So basically--how do I combine the count function with the selected >> function? >> >> Thanks in advance! >> >> -- >> You received this message because you are subscribed to the Google Groups >> "commcare-users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to commcare-user...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > >