FAQ | In a formula, how can I check if a variable belongs to a set of values?#
A common need when using Formulas is to check whether a variable (generally, a column) belongs to a set of values.
For example, you may want to check if my_column has value 1, 2, or 3. To do that in a formula, use the arrayContains function:
arrayContains([1,2,3], my_column)
In other words, instead of checking if “my_column is in [1,2,3],” you check if “[1,2,3] contains my_column.”
It may be useful to recall the reference documentation on 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"))
If you wanted to replace specific values with a variable, normal variable syntax rules apply.
arrayContains([${my_var1}, ${my_var2}, 3], my_column)
