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

If Statements

Level 2
If Statements

Hi, Im trying to write an if statement based on a number of variables. 

I have the following formula written

On my GPA_Tool column I only want to take the first 3 digits.



However I have other values I would like to include, more numbers other than the 166. for example if the if(arrayContains(splitByLengths(GPA_Tool,3),"166" or then if it is "183","187",189" etc.....


0 Kudos
3 Replies

Hi David,

When having more than 5 else ifs on a statement, using a switch case() statement instead becomes a better option due to speed, clarity, etc. (Note this assertion is not DSS specific, but generally coding wise).

As a result, an option is to create a python recipe where starting in Python 3.10 the 'case' keyword was added. If you do not have that Python version, another option is to use the 'Switch case' processor in a Prepare recipe.

For example:


Level 2

Thanks very much

0 Kudos

@David_Mellamphy ,

Another way you might lookup these values is by doing join to a detail table with the replacement values.  Create a short table with your numeric values in one column and your replacement/new values in the second column. Then join the first column of this new  dataset to the original value in the original tables.  This can be particularly performant if your data is stored in a SQL database. If the list of replacements is long it can also be somewhat easier to manage these replacements over time.

just a thought.