HOW TO CREATE A STANDARD MACRO IN ALTERYX

by Gaia Fantini

At the Data School we met Macros a couple times now and I though I would draft a small recap that can be useful for anyone looking to start digging in the topic. Let's start with a bit of theory before going ahead and create a standard macro.

1.       What is a Macro?

A macro in Alteryx is essentially a set of tools built as a group that can be used in a workflow as a single tool. They are quite useful if you happen to find yourself repeatedly creating the same workflow: once saved, a macro can be inserted into any workflow and perform the same process that have been saved with, without having to create it again from scratch.

A macro can be saved similarly to a workflow, with a different file type: .yxmc

Once saved, a macro is easily accessed from the Tool Palette under the category Macro, or can be inserted into a canvas with a right-click.

2.       Types of Macros

Standard a set of tools is packed into a workflow and the instructions will be processed linearly when input into in a regular workflow

Batch this macro allows to group data into batches and process one batch at a time, running multiple times (one for each batch) creating an output after every run. This macro requires a Control Parameter Tool to configure.

Iterative this macro runs multiple times through every record until a set target is reached. If the condition is not met, it generates a loop, and repeat the process as many times as necessary or until a set limited number of iterations is met.

Location optimizer this macro runs multiple times to identify the optimal locations to add or remove from a locations networks.

3.       Creating a Macro

The first step to create a macro is to create a workflow with a specific dataset and test it. To save this workflow as a macro to have it readily available to use it with similar dataset, simply start by cutting the portion of workflow you want to be part of the macro, and paste it on a new workflow.

In this example I will calculate the total sales for some pet stores, and union it to the table.

Paste the workflow onto a new sheet, insert a new text input tool and paste in it a few sample rows from the original dataset to use as a test. Now right-click on the text input tool and choose Convert to Macro Input.

Note that the selected tool from the original workflow has not been included in the macro because it has been used to do a bit of clean up of the data, and since the intent is for the macro to be available to use with other dataset which might require different cleaning processes, it is no use to include it in the macro. The idea is that macros could be used as template for any dataset, and if cleaning is required, this would be done outside of the macro for each individual case. Add an output tool and run to see the result of the flow:

The input and output tool for macros are different and can be found under the Interface Tools tab

Now the macro is ready to be saved: look for the macro repository in your Alteryx Designer directory and save it here so he can be accessed from the Tool Palette or the canvas. Be careful and check that it has been saved with the correct file type.

Now, going back to the original workflow it is possible to delete it completely and insert the macro after the Select Tool instead. Running the workflow shows that the macro worked and the output of this single tool is the same of the four tool workflow created before.

An extra row with total sales has been added at the bottom of the table

This sequence of tools is now available to be used to calculate and union the total monthly sales for other stores without having to create the entire workflow. This is a simple macro with no configuration required, but it is still quite powerful.

It is worth to note that some of the tools in the palette are actually macros. Count Records for instance is a macro, with no configuration needed either. Many tools in the Preparation tab are macros, too. To check if a tool is in fact a macro, just drag it onto the canvas and look for the small plus sign at the bottom right corner:

Right-clicking on one of this tool allows to open the corresponding macros, to see in details how it is composed:

From the Interface Design Panel it is possible to configure a macro – when needed, reorganise the Questions and group them, see the tree map, and change the macro icon, which can be useful to group macros into categories and to easily recall the purpose for which it was created and its functionalities.

At the moment I only have a few macros in my repository, but I think a good exercise for the next time I create a workflow in Alteryx would be to try and think if the flow – or part of it - would make for a good macro that I could re-use and try to create it adaptable to different workflows. Hopefully I can come back on this blog with good news on this front!