Hi data enthusiast, I have just finished halfway through the 4-month intense training in The Data School. Throughout 8 weeks, I have done a lot with Alteryx and u know what, I realized that Alteryx could be used as a programming language in some cases. In this blog, I will show you how we can use Alteryx to implement basic Python commands. So bear with me and fasten your seatbelts guys!

IF Statement

This is the most fundamental decision-making statement, by checking a specified condition, you can set the action for the computer using the then and else statement after that. Of course, in Alteryx, you can also do it with just one tool – The Formula tool, my favorite.

As you can see in the example above, a simple If statement can be easily implemented within a Formula tool. And here is the result:

      

Switch Statement

This is a type of selection control mechanism used to allow the value of a variable or expression to change in some specific cases. In Alteryx, with the same tool as the IF Statement, you just need 1 Formula tool:

In this example, I used the switch statement in Alteryx to change the First field value. Here is the result:

   

For/While Loop

For loop and while loop are 2 control flow statements with some actions for every iteration of the loop,  however, there is just one difference between them. When For loop will have a specific number of iterations,  the While loop has a condition statement to consider whether it should continue running or not. In Alteryx, there are many ways to execute for loop or while loop, depending on the context. However, I will introduce you to a universal way to execute those loops. It could be over-complicated however using this way, your loop will be executed despite of the circumstances. That’s using an Iterative Macro

While Loop

Just one tool, Easy peasy:

Just kidding haha. Here is what actually happened inside the blue tool :

The workflow above is the simple macro I have written in order to get the While loop run. The basic idea of this example is we have a variable as 2 (named Value), then we will double it until Value > 100. In the workflow above, I have the first blue tool named Formula to double the value, then the second blue tool named Filter will check the condition then if it is wrong then continue the iterative macro, then just put the Iteration Input and Output in the Interface Designer (Open by Ctrl + Alt + D):

Then insert your macro into the workflow and there you have the result:

   

For loop

For loop is actually very similar to this, just one difference is instead of using a filter tool to check the stop condition, you can set the limited number of iterations:

Changing this parameter will make sure that the macro will run only 5 iterations and the result will be 2 power to 6 times (Iteration start at 0):

   

Python Tool

One more undeniable evidence for my thought is the fact that Alteryx has a Python tool. You can just import Alteryx in Python and run your code using this tool:

With this tool, you can basically forget what I said in this blog, enjoy your collaboration of Python and Alteryx.

And that’s it for today. See you guys in the next blog. Hope you enjoy data enthusiasts!

The Data School
Author: The Data School