Counting of Single Select Choices

Am trying to achieve how I can Inform the Mobile Worker that a Particular group has completed all the specific module lessons. The Lessons for a particular module are captured as Multiple Choices (Single select), where each single follow-up covers one Lesson in a Module and therefore each visit they will select the lesson for that particular day until all lessons are completed.
I tried to use the count-select() function so that I can count and inform the worker how many lessons have been covered for the a specific group since these groups act as cases. Also at the end if a group have covered all the 5 lessons, then a worker should be notified when they select that group that the group completed all the five lessons.
Thank you.

I’m sorry, your description is a bit confusing…

Lets say you have 2 modules with each 5 forms. the forms are the lessons, and the modules are a group of lessons that your beneficiaries have to complete.

If you use different cases for each module, then you can place a hidden value (ie count_lessons_done) in the form and increment it at the end of each lesson (in the calculate field you place coalesce(count_lessons_done, 1)+1).

When the counter reach 5, then the module is complete and you can place an icon or a flag in the case list.

Does that match your needs ?


Thank you Michel
As this is exactly what I really want to achieve, though does this work for

Refering to the attached image, I have different Modules within each Module, I have Lessons, so can I use the coalesce(count_lesson_done) command

Ok, what you are showing me is not at all what I had in mind. So forget what I was saying before.

My advise is to use multiple selects (checkboxes) in place of single select (radio buttons) so that the user can enter multiple lessons if the mother as attended various lessons in 1 modules.

Doing so, you will be able to use the count-select() function.

Please refer to this page to see how CommCare functions operate :


Hello Michel,
A reminder is that all Lessons in a Module are taught Independently, and also they are in a follow-up form whereby each of the “Lesson Variable” is captured as a “CASE PROPERTY”. (Literally a group will not have more than one lesson being taught a Day, and that is why we opted for the Single Select “Radio Buttons” instead of “Check-boxes”)
I had tried using a HIDDEN VALUE “count(#form/module6[#form/module6/Module_6_lessons=‘Lesson_1:_Healthy_baby_play_areas’])”
For each particular Lesson,then at the end I create another hidden value to do the summation of all the hidden values (created for each lesson). So, if a module has FIVE Lessons, then the hidden value doing the overall summation has to equal to 5, then a Flaging Comment will appear to inform the Trainer that the Group has completed all the lessons in that particular Module.

Does that work for you ?


The Challenge am having is that I made the Hidden values Case properties and so that calculation does not work well. I still need your Assistance, Michel

Ok. if this isn’t working, then you need to change something.

First, hidden values and Case properties are two différent things. We are talking about hidden values inside a form. Case properties are in the game once a form has been validated and are updated by anything (hiden value, text question, multiple choice, etc.).
hidden values cannot be called (for calculation or for display) outside a form. Case properties can be called inside a form by the mean of hidden values.

Now, in order to register the lessons attended by mothers, you will open a form. The same form for every mother (or groups of mother, I don’t know).
In this form you will have your modules as displayed in your screenshots. For each modules, you will define the lessons, same as you did. But you will define them as MULTIPLE SELECT in place of single select.
In the case management of this form, you will save does multiple select as case properties for you case type (mother I guess ?).
Back to the form, you will load the case properties you’ve just registered as default for the multiple select questions. That way, each time you will open the form for a given mother, you will find the answer you entered the last time she took a lesson.
Those answers are editable so that you can add a lesson and the form will register the added information in the case property upon validation.

Once you understand this, you will be able to create hidden values inside your form to count the number of lessons per modules as described sooner in this conversation using the count-select() function referencing the multiple select question as argument. Then register this hidden value into another case property and you will be able to inform the worker how many lessons have been covered for the a specific group and inform them that a group has covered all five 5 lessons.

This is the best I can do to you… I hope you’ll manage what you’re looking for.



Thank you, Michel. Because it does solve the issue, though one challenge I have is that;
Am having trouble of calling the value stored in the Hidden value that counts because I have stored it as a case, and it seems once a variable is stored as a case property then its by default converted into string. So, What I want to do is that; Lets say Module 1 all Lessons (Four Lessons) were taught, thus Hidden Value that dose the count-select(module_lessons) is now 4, but since it was saved as a case property I have discovered that all case properties are saved as STRING and yet I want to call back the variable as an INTEGER. My Question is, how can I turn the case (STRING) into Numeric (INT), so that I can use it in validation whereby a mobile worker can not open a Module again once all lessons were completed.


You can use the function int()

In case you have decimals, you can replace this function by double()


Hi Michel,
I have tried the int() Function, but I still cannot get the value that I want.
Any ideas of how I can handle this; int(#case/completed_module_1), while
completed_module_1 = if(#form/module_1_lessons_1 = 4, 1, 0) whereby
module_1_lessons_1 = count-selected(#form/module1/module_1_lessons).
Waiting on your Reply Michel
Thank You for your Support.


If #form/module1/module_1_lessons is a multiple choice question, then count-selected(#form/module1/module_1_lessons) is an integer. If so, completed_module_1 will indeed be an integer. So no need to cast it into an integer using int().

Maybe your problem is elsewhere…

Depending on your CommCare plan, you can ask someone from dimagi to have a look at your project…


Thank you very much, Michel