Find if a string is in an array with a formula

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
    edited July 2024 Answer ✓

    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

  • JuanE
    JuanE Dataiker, Registered, Moderator Posts: 45 Dataiker

    Would you mind sharing your solution to the above? It may be interesting to other users

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

    I shared it in the question already

    I wanted to do like in stack overflow when you can ask and answer your question on the same place but I don't think it's possible here so i did this.

    But sure i'll write the answer in the validated answer as well.

  • JuanE
    JuanE Dataiker, Registered, Moderator Posts: 45 Dataiker

    Thank you for your contribution!

Setup Info
    Tags
      Help me…