Find if a string is in an array with a formula

Solved!
Madar
Level 2
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 ! 

 

 

0 Kudos
1 Solution
Madar
Level 2
Author

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 ๐Ÿ™‚ 

 

View solution in original post

4 Replies
Madar
Level 2
Author

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 ๐Ÿ™‚ 

 

JuanE
Dataiker

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

0 Kudos
Madar
Level 2
Author

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
Dataiker

Thank you for your contribution!

Labels

?

Setup info

?
A banner prompting to get Dataiku