Nested if else condition

anthony
Level 2
Level 2
Nested if else condition

I have a scenario where I have create a if else condition in dataiku which is having around 6000 conditions. The scenario is like:

if ( col1 == 'A' , 1 ,if( col1 == 'B',2, if(col1 == 'C',3,0)))

The formula option with if condition gives stackoverflow error. Is it the length of the if else conditions that is causing the error or can it be something else.

Also I was trying find and replace as an alternative option, is there an option in find and replace to enter all these 6000 strings and its replacements from a file instead of manually doing a copy paste of each of these conditions. Also whats the actualuse of 'raw text edit' option 

 

Thanks

0 Kudos
1 Reply
tgb417
Neuron
Neuron

@anthony ,

Welcome back to the Dataiku Community.

Yes, it is likely that 6000 nested if-else statements, will cause you a problem.  6-10 nested ifs I've done but not 6000.  (It would be interesting to know from staff what the "()" Nesting limit of the shaker language used for Visual Recipies might be.)

Another way that may be helpful to achieve the goals you appear to be going for is to use a join recipe.

In your example above, I see that the column you are evaluating is being held steady on "col1".   If that is your actual intent and not just a simplified example.

Then, you might create a manually edited table in Dataiku OR import an Excel Spreadsheet in a two column format seen below:  

Col1_ValueNew_Column_Value
A1
B2
C3
......

(The first column contains the value you are looking for in your table.  The second with the value you wish to put in the new table column.)

This table would extend to your 6000 entries or way further.   

You could use a join visual recipe to connect this "business logic" table to your original table.  When the value in the "Col1_Value" is the same as the value in the "Col1" or your original table.  The join recipe would connect the two records and add the value as a new column in the resulting table.  This is sort of like VLookup that you might be accustomed to in MS Excel.  (But more powerful in some ways.)

Hope that helps a bit.

--Tom
A banner prompting to get Dataiku DSS
Public