Contains(), ContainsAll(), ContainsAny()

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.

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) .

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.

It doesn’t work @BenLee

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.

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.

1 Like