Survey banner
The Dataiku Community is moving to a new home! We are temporary in read only mode: LEARN MORE

Writing an if statement to check if a value is not contained in an array

Solved!
7mxd
Level 2
Writing an if statement to check if a value is not contained in an array

Hey everyone!

Currently I am using the prepare recipe, and specifically the Create if, then, else statements processor. For one of the if statements, I want to write an if statement that check if each value in a specific column is not contained in a given array. I know that I can compare a value with another value; however, I would like to compare a value with an array of values (string in this case).

Is there any way to do that?

Best regards,
Ahmed 
0 Kudos
1 Solution
AlexT
Dataiker

Hi,
I don't see a way to do this with if then else processor but instead you can use a formula:
You can use "arrayContains" https://doc.dataiku.com/dss/latest/formula/index.html

if(arrayContains([2010, 2020, 2030], year), "true", "false") 

Thanks

View solution in original post

5 Replies
AlexT
Dataiker

Hi,
I don't see a way to do this with if then else processor but instead you can use a formula:
You can use "arrayContains" https://doc.dataiku.com/dss/latest/formula/index.html

if(arrayContains([2010, 2020, 2030], year), "true", "false") 

Thanks

7mxd
Level 2
Author

That's clear Alex! Thank you! Appreciate your help!

0 Kudos
tgb417

@7mxd 

I’m not clear that this can be done using the create, if, then else visual prepare recipe step.  I am wondering if you can use the formula recipe step to get what you want done.  

here is a post that seems to be related to your use case 

https://community.dataiku.com/t5/General-Discussion/Dataiku-formula-language-for-SQL-IN/m-p/16270/hi... 

If you want to use the create, if then else step for other reasons you might simply use the formula step to create a temporary Boolean column with the answer if you found or did not fine that item you were looking for.  Then in the create if then else column you would simply reference the temporary column you created. 

 

--Tom
MayeulR
Dataiker

Hello, 

You can achieve this with the Create...If..then processor by using the operator "is none of the strings".

Best,

 

0 Kudos
7mxd
Level 2
Author

I am already using the formula processor; however, I thought that the if, then, else processor might give a more accurate result.

Thank you so much for your response. I appreciate your help!

0 Kudos