# Distinct Count of Answers in Repeat Group

**URL:** <https://forum.dimagi.com/t/distinct-count-of-answers-in-repeat-group/10995>\
**Category:** Users\
**Created:** [July 24, 2024, 8:53am UTC](https://forum.dimagi.com/t/distinct-count-of-answers-in-repeat-group/10995 "2024-07-24T08:53:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vmuoio](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/v/e495f1/32.png) [@vmuoio](https://forum.dimagi.com/u/vmuoio)\
**Post date:** [July 24, 2024, 8:53am UTC](https://forum.dimagi.com/t/distinct-count-of-answers-in-repeat-group/10995/1 "2024-07-24T08:53:45Z")

</div>

Hello! I am have a form that is tracking attendance at project events. There is a repeat group based on the # of participants. For each participant, there is a question "What organization are they from?" which is a multiple choice pulling from a lookup table based on a caselist of organizations.

What I want to do is add a hidden value outside of the repeat group that counts the numer of unique organizations that were selected within the repeat group iterations. Somehow I can't figure out how to do this.

What I have tried is below, but I am getting an error. Any advice would be very helpful!

 ![image](https://dimagi.b-cdn.net/uploads/default/original/2X/1/1cc327f9f184c5189a1f0f3f99bd40619412999c.png)  
 ![image](https://dimagi.b-cdn.net/uploads/default/original/2X/a/a077257cb5ceb4b81bef789af6c0fdadc1a1be51.png)  
 ![image](https://dimagi.b-cdn.net/uploads/default/original/2X/2/25bd7bef8a8c84488ac88372ae3aa60e92dab80b.png)

---

<div class="post-metadata">

**Author:** ![Mazz](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/mazz/32/1004_2.png) [@Mazz](https://forum.dimagi.com/u/Mazz)\
**Post date:** [July 24, 2024, 8:57am UTC](https://forum.dimagi.com/t/distinct-count-of-answers-in-repeat-group/10995/2 "2024-07-24T08:57:53Z")

</div>

try count-selected instead  
count expects a nodeset.  
distinct-values returns a space separated value

---

<div class="post-metadata">

**Author:** ![vmuoio](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/v/e495f1/32.png) [@vmuoio](https://forum.dimagi.com/u/vmuoio)\
**Post date:** [July 24, 2024, 9:03am UTC](https://forum.dimagi.com/t/distinct-count-of-answers-in-repeat-group/10995/3 "2024-07-24T09:03:42Z")

</div>

Oh thanks! Just to understand better - do you mean "count-selected(distinct-values...." or just "count-selected"?

Would count-selected return the "unique count" or will there be duplication based on the values. For example, if more than 1 participant is from "NGOX", I only want it to be counted once in the hidden value. I was looking at this originally:

 ![image](https://dimagi.b-cdn.net/uploads/default/original/2X/7/79a22b461b9add37410e60f543c357f0833716cb.png)

[https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143957589/CommCare+Functions#distinct-values](https://dimagi.atlassian.net/wiki/spaces/commcarepublic/pages/2143957589/CommCare+Functions#distinct-values)

---

<div class="post-metadata">

**Author:** ![Mazz](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/mazz/32/1004_2.png) [@Mazz](https://forum.dimagi.com/u/Mazz)\
**Post date:** [July 24, 2024, 9:23am UTC](https://forum.dimagi.com/t/distinct-count-of-answers-in-repeat-group/10995/4 "2024-07-24T09:23:30Z")

</div>

> [@vmuoio](#):
>
> "count-selected(distinct-values...."

this one  
if you look at the example, it actually uses join as well I guess to keep the spaces between the choices.  
try it the way they did it there. Multiple choice questions return a space separated list like the "a a b b c c c c"  
remember that these values will be whatever you have defined in the value attribute of the lookup table question. so if they are unique, it will return the same values.

---

<div class="post-metadata">

**Author:** ![Mazz](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/mazz/32/1004_2.png) [@Mazz](https://forum.dimagi.com/u/Mazz)\
**Post date:** [July 24, 2024, 9:24am UTC](https://forum.dimagi.com/t/distinct-count-of-answers-in-repeat-group/10995/5 "2024-07-24T09:24:04Z")

</div>

so it'll be count-selected(join(distinct-values

---

<div class="post-metadata">

**Author:** ![vmuoio](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/v/e495f1/32.png) [@vmuoio](https://forum.dimagi.com/u/vmuoio)\
**Post date:** [July 24, 2024, 11:18am UTC](https://forum.dimagi.com/t/distinct-count-of-answers-in-repeat-group/10995/6 "2024-07-24T11:18:06Z")

</div>

Thank you so much!!!! This worked!!!

count-selected(join(" ", distinct-values(#form/attendance/staff\_reg/organization)))
