Survey banner
Switching to Dataiku - a new area to help users who are transitioning from other tools and diving into Dataiku! CHECK IT OUT

how to use multiple if functions to create columns

Solved!
abalo006
Level 2
how to use multiple if functions to create columns
 

I have 2 columns "label" and "value" and I'm trying to create a third column called category by using the contains function on the label column.

I can use if( contains(label,"food"),"food","not food") which basically says if the label contains food, then food else not food.

but how can I use multiple contains within an if function to create multiple different category names dependent on if the category is contained in the label?

is that possible? and if so, how would I accomplish that?

I've attached my desired output below.

test.PNG


Operating system used: windows


Operating system used: windows

0 Kudos
1 Solution
SarinaS
Dataiker

Hi @abalo006,

While it is possible to use the formula language with nested "if" statements to accomplish this, I would suggest trying out the visual if-else processor available in the prepare recipe. You can find a detailed example of how to set up this processor here: https://knowledge.dataiku.com/latest/data-preparation/prepare-recipe/tutorial-visual-logic-processor... 

This allows for easy case-insensitivity and complex nested conditions, so is probably a good fit for your use case. Here is an example of using this processor:

Screenshot 2024-04-25 at 5.17.21 PM.png

Just to note, the output column must exist before using the "If-then-else" processor, and you can use a Formula step to create a dummy column before using this processor.

I hope that information is helpful, please let us know if you have any questions about this approach.

Thank you,
Sarina 

 

View solution in original post

1 Reply
SarinaS
Dataiker

Hi @abalo006,

While it is possible to use the formula language with nested "if" statements to accomplish this, I would suggest trying out the visual if-else processor available in the prepare recipe. You can find a detailed example of how to set up this processor here: https://knowledge.dataiku.com/latest/data-preparation/prepare-recipe/tutorial-visual-logic-processor... 

This allows for easy case-insensitivity and complex nested conditions, so is probably a good fit for your use case. Here is an example of using this processor:

Screenshot 2024-04-25 at 5.17.21 PM.png

Just to note, the output column must exist before using the "If-then-else" processor, and you can use a Formula step to create a dummy column before using this processor.

I hope that information is helpful, please let us know if you have any questions about this approach.

Thank you,
Sarina 

 

Labels

?
Labels (1)
A banner prompting to get Dataiku