Find if a string is in an array with a formula
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 !
Best 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
-
Would you mind sharing your solution to the above? It may be interesting to other users
-
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. -
Thank you for your contribution!