Counting multiple select

I am writing a code wherein a question has an option of multiple
responses. The no of times each response is entered is to be counted.
I am trying this syntax
if(selected(questions/data, "4"),1,0) and then this is summed after the
loop. However, whenever this is run in cloudcare i get an error, syntax not
identified.

Please help.

Thanks,
Prachi

Hi Prachi,

I also have multiple choice questions in forms in my apps that I need to
count and this is how I have done it. I created a case property for the
choice in the form that registers a case and set the calculate condition to
0. Then, in the form with the multiple choices question I created 2 hidden
values labelled prev_choice and new_choice. In the calculate condition of
the new_choice I added the prev_choice + 1, and in the display condition I
specified that it should only happen if that choice was selected eg.
selected(/data/question, 'choice"). On the case management side; load the
case property choice into prev_choice and load new_choice to the case
property. This will now count the number of times the option is chosen
from the list.

Hope this helps!

Ameera

··· On Tuesday, 10 February 2015 04:55:31 UTC+2, Prachi Patel wrote: > > I am writing a code wherein a question has an option of multiple > responses. The no of times each response is entered is to be counted. > I am trying this syntax > if(selected(questions/data, "4"),1,0) and then this is summed after the > loop. However, whenever this is run in cloudcare i get an error, syntax not > identified. > > Please help. > > Thanks, > Prachi >

Forgot to mention that you will need to follow the above for each option.

··· On Tuesday, 10 February 2015 04:55:31 UTC+2, Prachi Patel wrote: > > I am writing a code wherein a question has an option of multiple > responses. The no of times each response is entered is to be counted. > I am trying this syntax > if(selected(questions/data, "4"),1,0) and then this is summed after the > loop. However, whenever this is run in cloudcare i get an error, syntax not > identified. > > Please help. > > Thanks, > Prachi >

Prachi,

It sounds like you're looking for the count-selected() method outlined here?

https://confluence.dimagi.com/display/commcarepublic/CommCare+Functions#CommCareFunctions-count-selected

-Clayton

··· On Tue, Feb 10, 2015 at 2:09 AM, Ameera Hamid wrote:

Forgot to mention that you will need to follow the above for each option.

On Tuesday, 10 February 2015 04:55:31 UTC+2, Prachi Patel wrote:

I am writing a code wherein a question has an option of multiple
responses. The no of times each response is entered is to be counted.
I am trying this syntax
if(selected(questions/data, "4"),1,0) and then this is summed after the
loop. However, whenever this is run in cloudcare i get an error, syntax not
identified.

Please help.

Thanks,
Prachi

--
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.