Find if a string is in an array with a formula

Options
Madar
Madar Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Registered Posts: 6

I wanted to use a prepare recipe instead of a python code one to do some error handling (for some maintenance reason).

One thing i tried to do was to reproduce this line from python :

if "str" in array_of_str :

// do something
else :
// do an other thing

Unfortunately, it's a little bit more complicated to do with dataiku formula. Contains works only with string, in doesn't work, and doing one if for each element of the array is not a scalable solution.

So, here is what i came up with :

if( arrayContains( forEach( [], item, item==column),"true"),column,"ERROR")

Don't forgot to replace the [] and name of the variable with yours

Hope I helped !

Tagged:

Best Answer

  • Madar
    Madar Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Registered Posts: 6
    Answer ✓
    Options

    Solved it above, but just in case :

    if( arrayContains( forEach( [], item, item==column),"true"),column,"ERROR")

    Don't forgot to replace the [] and name of the variable with yours

Answers

Setup Info
    Tags
      Help me…