# Contains(), ContainsAll(), ContainsAny()

**URL:** <https://connect.superhuman.com/t/contains-containsall-containsany/17183>\
**Category:** Showcase & Tips\
**Created:** [July 14, 2020, 3:17am UTC](https://connect.superhuman.com/t/contains-containsall-containsany/17183 "2020-07-14T03:17:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_Lee](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/ben_lee/32/49867_2.png) [@Ben\_Lee](https://connect.superhuman.com/u/Ben_Lee)\
**Post date:** [July 14, 2020, 3:17am UTC](https://connect.superhuman.com/t/contains-containsall-containsany/17183/1 "2020-07-14T03:17:37Z")

</div>

## **Contains** (value, search)

Checks if a list contains any value from a list

`Contains("Dog", "Cat", "Mouse")` ⟶ False

`Contains("Dog", "Cat", "Mouse", "Dog")` ⟶ True

`List("Dog", "Giraffe").Contains("Cat", "Mouse", "Dog")` ⟶ True

#### INPUTS

value – A value or list of values to search in

search… – A value or list of values to search for

#### OUTPUT

Outputs True if any value in search exists in value.

* * *

## **ContainsAll** (value, search)

Checks if a list contains all values from a list

`ContainsAll("Dog", "Cat", "Mouse")` ⟶ False

`ContainsAll(List("Cat", "Rabbit"), "Cat", "Mouse")` ⟶ False

`List("Cat", "Mouse", "Rabbit").ContainsAll(List("Cat", "Mouse"))` ⟶ True

#### INPUTS

value – A value or list of values to search in

search… – A value or list of values to search for

#### OUTPUT

Outputs True if all values in search exists in value.

* * *

## **ContainsOnly** (value, search)

Checks if a list contains only values from a list

`ContainsOnly("Dog", List("Dog", "Mouse"))` ⟶ False

`List("Dog", "Mouse", "Cat").ContainsOnly("Cat", "Mouse")` ⟶ False

`List("Dog", "Mouse").ContainsOnly("Mouse", "Dog")` ⟶ True

`ContainsOnly(List("Dog", "Dog"), "Dog")` ⟶ True

#### INPUTS

value – A value or list of values to search in

search… – A value or list of values to search for

#### OUTPUT

Outputs True if only values in search exist in value.

---

<div class="post-metadata">

**Author:** ![Jhon\_Albert](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/jhon_albert/32/24972_2.png) [@Jhon\_Albert](https://connect.superhuman.com/u/Jhon_Albert)\
**Post date:** [February 11, 2022, 4:41pm UTC](https://connect.superhuman.com/t/contains-containsall-containsany/17183/2 "2022-02-11T16:41:44Z")

</div>

I have two sets, A and B, of the same type.  
I have to find if A contains any element from the set B.  
What would be the best way to do that without iterating over the sets?  
The Set library has `contains(object)` and `containsAll(collection)` ,  
but not `containsAny(collection)` .

---

<div class="post-metadata">

**Author:** ![Ben\_Lee](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/ben_lee/32/49867_2.png) [@Ben\_Lee](https://connect.superhuman.com/u/Ben_Lee)\
**Post date:** [February 11, 2022, 5:35pm UTC](https://connect.superhuman.com/t/contains-containsall-containsany/17183/3 "2022-02-11T17:35:26Z")

</div>

Hi @Jhon_Albert,

`Contains()` is a “contains any” formula. So the following should work for you.

`[List A].Contains([List B])`

Give that a try and let us know if it doesn’t work.

---

<div class="post-metadata">

**Author:** ![Jhon\_Albert](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/jhon_albert/32/24972_2.png) [@Jhon\_Albert](https://connect.superhuman.com/u/Jhon_Albert)\
**Post date:** [March 18, 2022, 10:29am UTC](https://connect.superhuman.com/t/contains-containsall-containsany/17183/4 "2022-03-18T10:29:57Z")

</div>

It doesn’t work @Ben_Lee

---

<div class="post-metadata">

**Author:** ![Jean\_Pierre\_Traets](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/jean_pierre_traets/32/16275_2.png) [@Jean\_Pierre\_Traets](https://connect.superhuman.com/u/Jean_Pierre_Traets)\
**Post date:** [March 18, 2022, 12:14pm UTC](https://connect.superhuman.com/t/contains-containsall-containsany/17183/5 "2022-03-18T12:14:49Z")

</div>

Dear @Jhon_Albert,

It would be of great support if you could share a dummy doc showing what exactly doesn’t work or give you the expected outcome.

Thank you.

---

<div class="post-metadata">

**Author:** ![Ben\_Lee](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/ben_lee/32/49867_2.png) [@Ben\_Lee](https://connect.superhuman.com/u/Ben_Lee)\
**Post date:** [March 19, 2022, 1:03am UTC](https://connect.superhuman.com/t/contains-containsall-containsany/17183/6 "2022-03-19T01:03:05Z")

</div>

Like like I answered too quick, sorry about that. Give this a try.

`[List A].Filter([List B].Contains(CurrentValue))`

Something like that should work. We need to check each item in List A individually against List B. You’re going to have to iterate through at least one of the sets.

---

<div class="post-metadata">

**Author:** ![Balint\_Drahota](https://yyz1.discourse-cdn.com/coda1/user_avatar/connect.superhuman.com/balint_drahota/32/10969_2.png) [@Balint\_Drahota](https://connect.superhuman.com/u/Balint_Drahota)\
**Post date:** [June 18, 2024, 5:19pm UTC](https://connect.superhuman.com/t/contains-containsall-containsany/17183/7 "2024-06-18T17:19:00Z")

</div>

In this case, why Contains() returns all rows when you can see not all contains that value?

 ![Screenshot 2024-06-18 at 19.14.51](https://global.discourse-cdn.com/coda1/original/3X/2/7/270af56ce37b9b982885a7efd45514541e663a07.png)

I realized this as part of FormulaMap filter criteria, which made 1 action instead the nr of rows, which makes me more doubtful about reliability…

---

<div class="post-metadata">

**Author:** ![anon1959570](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon1959570](https://connect.superhuman.com/u/anon1959570)\
**Post date:** [June 18, 2024, 5:40pm UTC](https://connect.superhuman.com/t/contains-containsall-containsany/17183/8 "2024-06-18T17:40:49Z")

</div>

Hi @Balint_Drahota

Try this. If you don’t use Count() as the Contains simply returns true or false the filter isn’t valid.

 ![image](https://global.discourse-cdn.com/coda1/original/3X/1/1/11305a01805d893f12858be120349ded53007320.png)
