How to count answers to a question in a repeat group in CommCare

commcare

I created a repeat group and I want to build logic to count the number of times a user choses certain answers to a specific question during the x number of times a repeat group repeats over itself. Can I use the count() function and build an if statement around it? How can I count specific number of times certain answer values were chosen for a single-select question?

Best Answer

You should be able to write the below:

count(#form/repeat_group_id[question_id = 'answer_a'])

You'd have to create different hidden values for each answer. And be sure to put those hidden values outside the repeat group.

"repeat_group_id" is the actual repeat group. "question_id" is the question withing the repeat group, so if that question is inside folders you'll need to include those in the path.