In a formula, how to check if a variable belongs to a set of values

Clément_Stenac
Clément_Stenac Dataiker, Dataiku DSS Core Designer, Registered Posts: 753 Dataiker
edited July 16 in Knowledge Base

A common need when doing formulas is to check whether a variable (generally, a column) belongs to a set of values.

For example, you may want to check if "mycolumn" has value 1, 2 or 3. To do that in a formula, use the arrayContains function:

arrayContains([1,2,3], mycolumn)

In other words, instead of checking if "mycolumn is in [1,2,3]", you check if "[1,2,3] contains mycolumn"

It is useful to remember the usual formula rules to refer the values of columns: https://doc.dataiku.com/dss/latest/advanced/formula.html#reading-column-values

For example, to do the same in a column named "my column" (note the space), you would use:

arrayContains(["a", "b", "c"], strval("my column"))

Tagged:
Setup Info
    Tags
      Help me…