Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

A Case Against Case Statements

TylerAV
5 - Atom

We've all been there, you have a complicated conditional statement. Nested if statements or extremely long case statements. They aren't fun and can be quite cumbersome. Worst off, they are hard to maintain. This is where Dynamic Replace comes into play. For those of you who have never used the tool, it can be used in a variety of manners, but the best feature is it's ability to process expressions that are contained in a column. Meaning, a column can have a written out Alteryx formula that can be converted from a string that shows the formula into the formula's solution. Example time:

 

Before - a generic case statement

TylerAV_0-1657803540749.png

After - storing expressions in a text input or you can keep it in a stored excel/csv file for easy editing!

TylerAV_1-1657803588921.png

 

I have also cut down the hard work so you can throw this macro into your own workflows without having to wrangle with the Dynamic Replace function. Now it's as easy as selecting the column that contains the expression, and this macro will return the solution.

TylerAV_2-1657803723496.png

 

Final Output

TylerAV_3-1657803744506.png

 

Easy and simple, no more nested logic! Hope this helps, see attached zipped workflow so you can test it out for yourself!

 

 

1 REPLY 1
Emmanuel_G
13 - Pulsar

@TylerAV Thanks for this tip !

Labels