<< Back

Alteryx Macros Made Simple: Standard Macro

This is the first in a series of blogs all about how to use macros in Alteryx. Simply put, a macro is a collection of workflow tools that are grouped together into one tool. Tools within the macro can be set up to be parameterised using a range of different interface tools. Any workflow can be turned into a macro, but what is most common is for a repeatable element of a workflow to be converted into a macro. There are 4 main types of macros that have a range of functions; Standard Macro, Analytic App, Batch Macro and Iterative Macro. Each blog in this series will explain how to create each type of macro and provide a couple of practical use cases. This blog will focus on the Standard Macro.

What you may not have noticed is that a lot of tools that are part of the core set of tools are actually macros. For example, if you right click on the ‘Histogram Tool’ and select ‘Open Macro’ a new workflow is opened which contains a set of data preparation tools and a set of Interface Tools. So, as you can see, all a macro is is just a set of tools that carry out a standardised task, all rolled up into one tool. The interface tools then enable parameterisation of certain tools in the macro, which can be seen once the macro is added to a new workflow.

There are a couple of ways you can turn your workflow into a Standard Macro. The first is to go to the canvas configuration pane and use the thumbnails to navigate to the ‘workflow’ tab. This section allows you to select what type of workflow you want. If you tick ‘Macro’ you should then have ‘Standard Macro’ automatically selected. Now when you save this workflow it will save as a macro. You’ll then be able to add it to another workflow and run the process created within the macro itself. The second method is just to add a Macro Input tool from the Interface tool section onto the canvas, the workflow will then automatically change to a Standard Macro.

What you may have noticed, when you switched to a Standard Macro, is that your tools in the workflow changed appearance a little. All tools will now have a little lightning bolt above them, and some may have a ‘Q’. These are specific interface inputs that will allow you to configure the parameterisation of each tool.

I’m now going to run through an example of a simplified Standard Macro, just to get you used to the configuration options available. The next blog in this series will then cover how you can develop your Macro and make it more interactive for other users in the form of an analytic app.

One function you may want from a macro is to allow users of the macro to select which fields they want to run through the process. We want the user to see a list of fields and be able to select which fields they want to put through the macro. Here’s a screenshot of the ‘Select Macro’

The 4 interactive tools in this Macro are; Macro Input, List Box, Action and Macro Output. I’ll describe the configuration of each of these in turn:

Macro Input

Initially you have 2 options, and depending on how you want the macro to be run you can either; select a simple text input layout, which you can design by clicking the ‘Edit Data’ button, or you can use a file as an input. The file input is more useful if you know that the data coming in to the Macro should have a certain set of fields coming into it.

You can then rename the input and give it an abbreviation which will be seen when you input the Macro to a new workflow.

The next couple of options are quite important and give you flexibility on how you want data to enter the macro. The ‘Show Field Map’ will list out every field that is in the Macro Input (from either the text input or file input). The user of the macro can then choose which field from their data should go in the place of the field in the Macro Input. You must be able to map to every field in the Macro Input from your data otherwise the macro will not run. If you want the Macro to be more dynamic you can uncheck the ‘Show Field Map’ and the fields will be replaced with whatever fields you have in your data, flowing into the macro.

If you’ve set up the Macro Input with a data set you want to keep consistent throughout the macro you may want to just make the Macro Input optional. This gives a bit of extra flexibility in case you want to change that data in the future. (If you want to keep some data in a macro static, you can always just use a normal input within the macro itself)

In this workflow, after the Macro Input tool, I’ve then added a Select tool.

List Box Tool

Next is the List Box tool, which we want to set up so that the user can choose fields to run through the Select tool from a list of the fields coming in via the Macro Input. When you drag the List Box tool into the workflow you need to connect it up to the Select tool. What you should see is that an Action interface tool is automatically added. I’ll describe the Action configuration after showing you the configuration for the List Box tool:

When you connect a List Box tool to a Select tool the default mode will be ‘Select Tool Mode’. Users of the macro will see a list of fields that they can choose from to be included or excluded from the macro. If you drag the Q underneath the Macro Input to the Q on top of the List Box tool the list values configuration will be locked to only include a list of fields from whatever data is put into the macro.

The properties section allows you to specify that only fields of certain data types should show up in the list of fields shown to the user of the macro. This can be useful if you only want users to add or remove numerical fields from a calculation. Or you may want users to only have the option to add or remove string fields.

Action Tool

Now, on to the Action tool! This is one of the most important tools in a macro as this is the tool you configure to make changes to other normal tools in a workflow. If you want to update an element of a filter, you’ll specify that using an Action tool. If you want to allow a user to dynamically rename a column, you’ll need to specify what part of a tool updated using an Action tool. In this example the Action tool is configured to ‘Update the Select Tool with a multi-select List Box’.

The other options in the Action tool will be discussed in the next blog in this series.

Macro Output

Lastly, if you want to bring data through the workflow and out the other side, you’ll need a Macro Output. You’ll be happy to hear the Macro Output doesn’t require any specific configuration. 🙂

Now you’ll want to save this macro somewhere so that it can be used in a workflow. If you go to File-Save, Alteryx automatically gives the workflow a different extension and will save as a .yxmc macro file:

This macro can then be added to a workflow by right-clicking in the canvas and going to Input then Macro. (You may then need to navigate to where the Macro was saved)

Use cases

The main use cases for Standard Macros are when you want to be able to re-use part of a workflow or you want add some level of interaction within a workflow. Standard Macros can be as simple as a repeatable data parsing process all the way to a macro that enables you to publish a data source to Tableau Server via the REST API.

If you go to the Alteryx Gallery you’ll find a whole library of Macros that people have uploaded. All Macros uploaded to the gallery are available for anyone to download and use in their workflows.

Resources

Here are a couple of articles that I think are also a good starting point for learning macros

https://community.alteryx.com/t5/Data-Sources/Macro-Show-Field-Map/td-p/13698

https://community.alteryx.com/t5/Publishing-Gallery/Macros-befuddle-me-Where-do-I-learn-how-to-make-them-Example/m-p/31122#M1021

https://www.youtube.com/watch?v=TD8E9e0GykY

 

Phillip Lowe

London, UK

3 thoughts on “Alteryx Macros Made Simple: Standard Macro

Leave a Reply

Your email address will not be published. Required fields are marked *