January 1, 2022

So You Want to Build Alteryx Macros (Part 1)

By John Emery

I was first introduced to Alteryx in January 2019 and instantly recognized the incredible power of the tool. If I had Alteryx in previous jobs, it would have saved me from writing thousands of lines of VBA and R code to prepare data for analysis.

Within a couple of months of picking up Alteryx for the first time I became Core, Advanced, and Partner certified, but I felt like a fraud. I knew what macros were, I understood their importance, but I was hesitant to make the dive to learn them properly. The thing is, macros in Alteryx are perhaps the most challenging aspect of the tool to master.

In this and subsequent posts, I will cover the different types of macros, why you would want to use them, and provide a detailed example of each type. By the end of the series, my hope is that you’ll be confident in your ability to build any type of macro in Alteryx.

What is a Macro?

The official Alteryx definition of a macro is:

A macro is a workflow or group of tools built into a single tool that can be inserted into another workflow. Create a macro to save an analytic process you perform repeatedly. Use the macro within a workflow without having to recreate the analytic process each time.

You may not be aware, but many tools that you regularly use are macros. To identify which tools are secret macros, navigate to Options → User Settings → Edit User Settings → Canvas → check the “Display macro indicators on tools.”

Once that’s done, go ahead and drag a Count Records tool onto the canvas. You’ll notice a small plus sign icon in the lower-right corner. This tells you that the tool is a macro.

Right-click a macro tool and you’ll see an option that reads “Open Macro: [XXX.yxmc].” Select this option and a new workflow will open where you can see “under the hood.”

The example above is a standard macro. We’ll take a deeper dive into this type of macro in Part 2. For now, be satisfied that this simple example contains the fundamentals of all macros:

  • A macro input, which feeds data from a standard workflow into the macro.
  • An analytic workflow that does something to the macro input.
  • A macro output, which feeds the data back into a standard (or another macro) workflow.

Types of Macros

As of version 2019.4, there are four types of macros available for use:

  • Standard Macro
  • Batch Macro
  • Iterative Macro
  • Location Optimizer Macro

Standard Macros

Standard macros are packaged groups of tools that are then inserted into a workflow. Like the example above, standard macros are perfect for tasks that are frequently duplicated. Rather than creating the same process many times, you can build a standard macro and reuse it as often as needed.

Batch Macros

A batch macro runs once for each record (or group of records) in the input data set. If you’re familiar with programming, a batch macro is similar to a for loop. One use of batch macros that I have personally used is for web scraping. If you have a base URL like “www.website.com/pageXXX” you can use a batch macro to pull records for various values of “XXX” in the URL.

Iterative Macros

Iterative macros keep running until the predetermined number of iterations has been met or until some other condition is met. Iterative macros are similar to while loops. I use these less often than batch macros but have seen them used for asset allocation problems (which we will see in Part 4).

Location Optimizer Macros

This is, by far, the least used and most specialized macro in Alteryx. Location Optimizer macros are special iterative macros that are used in network analysis to identify optimal locations.

Next Steps

As I mentioned above, I think macros are among the most difficult things to master in Alteryx. Standard macros aren’t bad, but batch and iterative macros can have multiple settings that need to be addressed. In addition, batch and iterative macros act like “black boxes” — data goes in and data comes out, but it’s difficult to tell what exactly is going on in the middle.

I hope after reading these blog posts that you’re less intimidated by these powerful-but-challenging features in Alteryx. Do you have more questions about Alteryx? Talk to our expert consultants today and have all your questions answered!

Data Coach is our premium analytics training program with one-on-one coaching from renowned experts.

Accelerate and automate your data projects with the phData Toolkit