# CountUnique not working

**URL:** <https://community.fibery.io/t/countunique-not-working/8128>\
**Category:** Bugs & Issues\
**Created:** [January 15, 2025, 10:37am UTC](https://community.fibery.io/t/countunique-not-working/8128 "2025-01-15T10:37:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NicolSpies](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/nicolspies/32/4317_2.png) [@NicolSpies](https://community.fibery.io/u/NicolSpies)\
**Post date:** [January 15, 2025, 10:37am UTC](https://community.fibery.io/t/countunique-not-working/8128/1 "2025-01-15T10:37:15Z")

</div>

I have a customer entity in the customer database with a collection of projects linked in the projects field. I want to count the number of linked projects which is in the “In Planning” workflow state.

I created a formula field for the customer entity with the formula"

```auto
Projects.CountUnique(State.Name = "In Planning")

```

The formula returns 1 if the customer has one or more projects in the collection regardless of the state of the projects. If the company has two or more projects attached and one of the projects has the state of “In Progress” the formula returns 2. Totally confusing.

What am I doing wrong or is this a bug?

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [January 15, 2025, 3:30pm UTC](https://community.fibery.io/t/countunique-not-working/8128/2 "2025-01-15T15:30:01Z")

</div>

Try this

```auto
Projects.Filter(State.Name = "In Planning").Count()

```

You don’t need CountUnique()

FYI CountUnique returns the number of items with a unique value for what is in parenthesis. Your expression (State.Name = “In Planning”) can return either true or false, so depending on what the linked Project states are, it will return either 1 or 2, depending if there exist any Projects which give true and/or any which give false.

---

<div class="post-metadata">

**Author:** ![NicolSpies](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/nicolspies/32/4317_2.png) [@NicolSpies](https://community.fibery.io/u/NicolSpies)\
**Post date:** [January 15, 2025, 7:35pm UTC](https://community.fibery.io/t/countunique-not-working/8128/3 "2025-01-15T19:35:38Z")

</div>

Thanks Chris, that is how I fixed it. Thanks for explaining the function, the results I get is line with your explanation.

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [April 29, 2025, 11:31am UTC](https://community.fibery.io/t/countunique-not-working/8128/4 "2025-04-29T11:31:14Z")

</div>


