CountUnique not working

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"

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?

Try this

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.

1 Like

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