how to use multiple if functions to create columns

abalo006 Registered Posts: 29

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.


Operating system used: windows

Operating system used: windows


Best Answer

  • Sarina
    Sarina Dataiker, Dataiku DSS Core Designer, Dataiku DSS Adv Designer Posts: 315 Dataiker
    Answer ✓

    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:

    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,

Setup Info
      Help me…