6 min read

[box type=”note” align=”” class=”” width=””]This article is an excerpt from a book written by Renato Baruti titled Learning Alteryx. In this book, you will learn how to perform self-analytics and create interactive dashboards using various tools in Alteryx.[/box]

Today we will learn Standard Macro that will provide you with a foundation for building enhanced workflows.

The csv file required for this tutorial is available to download here.

Standard Macro

Before getting into Standard Macro, let’s define what a macro is. A macro is a collection of workflow tools that are grouped together into one tool. Using a range of different interface tools, a macro can be developed and used within a workflow. Any workflow can be turned into a macro and a repeatable element of a workflow can commonly be converted into a macro.

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 navigate to the Workflow tab. This is where you select what type of workflow you want. If you select 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. The following screenshot shows the selection of a Standard Macro, under the Workflow tab:

Workflow Configuration

Let’s go through an example of creating and deploying a standard macro.

Standard Macro Example #1: Create a macro that allows the user to input a number used as a multiplier. Use the multiplier for the DataValueAlt field. The following steps demonstrate this process:

Step 1: Select the Macro Input tool from the Interface tool palette and add the tool onto the canvas. The workflow will automatically change to a Standard Macro.

Step 2: Select Text Input and Edit Data option within the Macro Input tool configuration.

Step 3: Create a field called Number and enter the values: 155, 243, 128, 352, and 357 in each row, as shown in the following image:

Alteryx Designer

Step 4: Rename the Input Name Input and set the Anchor Abbreviation as I as shown in the following image:

Macro Input 4 Configuration

Step 5: Select the Formula tool from the Preparation tool palette. Connect the Formula tool to the Macro Input tool.

Step 6: Select the + Add Column option in the Select Column drop down within the Formula tool configuration. Name the field Result.

Step 7: Add the following expression to the expression window: [Number]*0.50

Formula 5 - Configuration

Step 8: Select the Macro Output tool from the Interface tool palette and add the tool onto the canvas. Connect the Macro Output tool to the Formula tool.

Step 9: Rename the Output Name Output and set the Anchor Abbreviation as O:

Macro Output 3

The Standard Macro has now been created. It can be saved to use as multiplier, to calculate the five numbers added within the Macro Input tool to multiply 0.50. This is great; however, let’s take it a step further to make it dynamic and flexible by allowing the user to enter a multiplier. For instance, currently the multiplier is set to 0.50, but what if a user wants to change that to 0.25 or 0.10 to determine the 25% or 10% value of a field. Let’s continue building out the Standard Macro to make this possible.

Step 1: Select the Text Box tool from the Interface tool palette and drag it onto the canvas. Connect the Text Box tool to the Formula tool on the lightning bolt (the macro indicator). The Action tool will automatically be added to the canvas, as this automatically updates the configuration of a workflow with values provided by interface questions when run as an app or macro.

Step 2: Configure the Action tool that will automatically update the expression replaced by a specific field. Select Formula | FormulaFields | FormulaField | @expression – value=”[Number]*0.50″. Select the Replace a specific string: option and enter 0.50. This is where the automation happens, updating the 0.50 to any number the user enters. You will see how this happens in the following steps:

Action 7 Configuration

Step 3: In the Enter the text or question to be displayed text box, within the Text Box tool configuration, enter: Please enter a number:

Text box Configuration

Step 4: Save the workflow as Standard Macro.yxmc. The .yxmc file type indicates it’s a macro related workflow, as shown in the following image:

Workflow

Step 5: Open a new workflow.

Step 6: Select the Input Data tool from the In/Out tool palette and connect to the U.S. Chronic Disease Indicators.csv file.

Step 7: Select the Select tool from the Preparation tool palette and drag it onto the canvas. Connect the Select tool to the Input Data tool.

Step 8: Change the Data Type for the DataValueAlt field to Double.

Step 9: Right-click on the canvas and select Insert | Macro | Standard Macro.

Step 10: Connect the Standard Macro to the Select tool.

Step 11: There will be Questions to select within the Standard Macro tool configuration. Select DataValueAlt (Double) as the Choose Field option and enter 0.25 in the Please enter a number text box:

Standard Macro 3 Configuration

Step 12: Add a Browse tool to the Standard Macro tool.

Step 13: Run the workflow:

US Chronic disease

The goal for creating this Standard Macro was to allow the user to select what they would like the multiplier to be rather than a static number. Let’s recap what has been created and deployed using a Standard Macro. First, Standard Macro.yxmc was developed using Interface tools. The Macro Input (I) was used to enter sample text data for the Number field. This Number field is what is used to multiply to what the given multiplier is – in this case, 0.50. This is the static number multiplier.

The Formula tool was used to create the expression to conclude that the Number field will be multiplied by 0.50. The Macro Output (O) was used to output the macro so that it can be used in another workflow. The Text Box tool is where the question Please enter a number will be displayed, along with the Action tool that is used to update the specific value replaced. The current multiplier, 0.50, is replaced by 0.25, as identified in step 20, through a dynamic input by which the user can enter the multiplier. Notice that, in the Browse tool output, the Result field has been added, multiplying the values for the DataValueAlt field to the multiplier 0.25. Change the value in the macro to 0.10 and run the workflow. The Result field has been updated to now multiple the values for the DataValueAlt field to the multiplier 0.10. This is a great use case of a Standard Macro and demonstrates how versatile the Interface tools are.

We learned about macros and their dynamic use within workflows. We saw how Standard Macro was developed to allow the end user to specify what they want the multiplier to be. This is a great way to implement the interactivity within a workflow.

To know more about high-quality interactive dashboards and efficient self-service data analytics, do checkout this book Learning Alteryx.

Learning Alteryx

 

Data Science fanatic. Cricket fan. Series Binge watcher. You can find me hooked to my PC updating myself constantly if I am not cracking lame jokes with my team.

LEAVE A REPLY

Please enter your comment!
Please enter your name here