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 Answer
-
Alexandru Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 1,226 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
Answers
-
tgb417 Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Neuron 2020, Neuron, Registered, Dataiku Frontrunner Awards 2021 Finalist, Neuron 2021, Neuron 2022, Frontrunner 2022 Finalist, Frontrunner 2022 Winner, Dataiku Frontrunner Awards 2021 Participant, Frontrunner 2022 Participant, Neuron 2023 Posts: 1,601 Neuron
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 caseIf 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.
-
Hello,
You can achieve this with the Create...If..then processor by using the operator "is none of the strings".
Best,
-
That's clear Alex! Thank you! Appreciate your help!
-
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!