Alteryx Macros vs Python Loops

by Chris Meardon

Macros come in three flavours: Standard, Batch and Iterative (if we ignore the final one that people never talk about). These have some parallels in Python, with which I am more familiar. I hope by highlighting the similarities and differences I may be able to help those in a similar position (and myself).

A standard macro seems to me like a function in Python. You have some block of operations, that may or may not have inputs and outputs, and you can use this anywhere is your workflow/ script. The operations are contained within this macro unless there is an output and you can have other macros within it. These are features of a function in Python.

Batch macros in Alteryx, are like functions inside for loops in Python. For each thing (in this case its a row) do something. Now this is slightly more challenging to explain because many of the standard tools in Alteryx act similarly to batch macros by default. They process the data row by row, or in other terms, the tool is applied for each row. A batch macro essentially makes this for loop two dimensional (or nested). For each row in my table, for each row in my batch macro, perform a process. But it’s not always this simple because you can have tools inside a batch macro that reference other rows in the table for example.

Iterative macros are like functions within while loops. They iterate a process until a condition is met. This condition is evaluated at the row level, which for me was quite confusing to understand at first. I think the iterations start on the first row of data and work their way down, as each point evaluating if the condition is met for that row or not. If it is met then it stops processing that row, but carries on with the rest. I think of iterative macros as essentially storing all these complete rows in a macro output like a bucket until it has finished with all the rows, and then outputs a unioned file of the results at that bucket.

My analogies are a bit crude but I hope this helps explain macros in a different way that maybe helps people with previous coding experience. I’ve mention python, but this of course applies across many languages.

I’d love to see simple Alteryx macros repeated as python code and then the opposite of starting at simple python loops and functions going to Alteryx.

© 2022 The Information Lab Ltd. All rights reserved.