Sign in or start a free trial to avail of this feature.
8. Creating Basic Macros in Alteryx
In this, the second half of the macro introduction, you will learn how to convert a workflow into a macro and then subsequently how to deploy that macro effectively.
Notes on before and after files
- This lesson has two separate Alteryx files that work in tandem, a macro file, and an fx workflow that is used for testing
- Begin the lesson with the macro file, and then move on to the fx workflow once the macro is complete
- When testing the macro, the macro file must be open, otherwise Alteryx will not be able to find it
- Macros must have a macro input and macro output tool on either end of the workflow
- These tools represent the input and output nodes that will appear on the macro tool
- Users can name the input and output tool as well as specify an abbreviation for the anchors
In the previous lesson, we introduced the concept of macros in Alteryx. We created a workflow that runs a foreign exchange API and begins with a text input tool.
In this lesson, our goal is to turn this workflow into a usable macro.
We'll accomplish this in three key steps.
First, we'll bookend our workflow with macro input and output tools. We'll then configure the macro settings in the Interface Designer.
Finally, we'll test the macro in a new workflow.
For the initial step, we'll add macro input and output tools to the workflow. We'll start by deleting the text input tool, navigating to the Interface tab, and replacing it with a macro input tool. The macro input tool will form the input node of our new macro, similar to various tools we've previously used.
We need to specify what data will come into this tool by either targeting a remote file or by setting up text input similar to the original setup. We'll click on the Edit Data instruction and enter the word Date as the field heading.
Now when we run our macro, we just need to run the relevant dates through this field in order to calculate the exchange rates against Euro on those days. To complete the macro, we must close it out by adding a macro output tool, again found on the Interface tab of the Tools palette. This forms the output node of the new tool. In the configuration windows for these macro tools, we can specify input and output names as well as an abbreviation for the nodes. In this case, we'll abbreviate the output node as O for output and the input node as D for date.
In the second step of this lesson, we'll take a look at the macro settings in the Interface Designer. If we go to the Properties tab, we can see there are various choices for the icon of the macro. We'll go with a standard icon for now. We'll now move on to step three and test out our macro. We'll save our macro and open up the fx_workflow_before canvas to see it in action. This canvas contains our daily sales data converted to the correct date format, together with the appropriate formats from both our Sales and Quantity fields. At this point, you may want to ensure that the input data tool is pointing to the Daily Sales data set. Before we pass the data through our macro, we'll need to get a list of individual dates in the data set. To that end, we'll connect a Summarize tool and group by date.
To connect our macro, we'll right-click on the canvas, select Insert, select Macro, and choose the FX macro.
We'll then connect the macro to the Summarize tool and run the workflow.
We can see that all 32 currencies are listed for each of the relevant days. The macro has pulled the relevant data, but now we need to use the FX rates to convert our data set to Euros. We'll bring a Join icon onto the canvas, connecting both the FX macro and the Select tool from the original data. In the configuration window, we'll join on the date and currency fields, rename the Rate currency field to local currency, and deselect the left date and currency fields, as we don't need them anymore. We'll then connect a formula tool to convert the local currency to the home currency. We'll name the field Euro Sales and enter the formula Sales divided by FX Rate.
We'll also change the data type to FixedDecimal, size 12.2.
We'll run the workflow, and see that we now have a new column that shows our sales figures in Euros. From here, we can easily create a useful sales report. What's more is that the macro is dynamic and will provide foreign exchange data for the sales reports we connect in the future, making this tool quite useful. Let's quickly recap this lesson. First, we bookended our workflow with macro input and output tools. We then viewed the macro settings in the Interface Designer. Finally, we tested the macro in a new workflow, using it to convert sales to Euro for a sales report.
In the last two lessons, we've introduced the concept of macros in Alteryx. These are complete workflows which can be wrapped up into a tool-like bundle and deployed within larger workflows. As we can see, macros are especially useful for specific tasks and repetitive functions. In the next lesson, we'll look at the other macro options available in Alteryx.