12. Running our Iterative Macro

 
Subtitles Enabled

Sign up for a free trial to access more free content.

Free trial

Overview

In the second of our lessons regarding iterative macros, you will learn how to complete the iterative macro workflow, and then deploy that macro to a relevant workflow.

Lesson Notes

 

Creating the Macro

  • While we are only searching for a trade area with 10 hotels, we need to set the filter to 11 as the tool counts the airport as a match
  • When configuring the join tool for the iteration, it’s important to make sure that all fields are correctly labelled
  • This macro has two outputs – one for all trade areas that meet the criteria, and one for the iteration

Transcript

In the previous lesson we created a framework for our iterative macro. This macro will return the smallest trade area for each airport that contains 10 hotels. So far we've brought our airport trade areas and hotels together with the spacial match tool. In this lesson we'll complete the macro and return a map of trade areas for all airports. We'll accomplish this goal by following four key steps. First, we'll use the filter tool to separate trade areas that have at least 10 hotels from those that have fewer than 10 hotels. Next, we'll need to configure the trade areas with fewer than 10 hotels to run through the macro for another iteration. Third, we'll configure the macro settings in the interface designer. Finally, we'll test the macro. We'll start by filtering our data into two separate sets, trade areas with at lease 10 hotels and trade areas with fewer than 10 hotels. From the Alteryx spacial course you may remember that spacial match tool splits incoming data into two sets, data that match the criteria and data that do not. If we run the workflow now, and click on the M matched output node, we can see that the dataset is empty. In other words, none of the hotels fall within a radius of 0.25 miles from the airports. If we click on the U output node we can see the full list of our 97 airports meaning that none of them have matching hotels. From here you might think that we can just add a filter tool to the M node and tell the macro to continue running until each airport has a trade area that contains 10 hotels.

Unfortunately if we do that now the macro will fail on the first run since it won't find any matching airport data from the incoming dataset. To get around this issue we'll carry the relevant information from both nodes forward using a summarize tool starting with the M node.

We'll group by airport abbreviation code IATA, then choose the first action for both airport name and trade area, count the number of hotels and show the last radius size.

We'll copy the tool, connect it to the U node, and then join the outputs with the union tool. We'll run the workflow and see that each airport is listed together with the number of hotels that fall within the trade area. We can see that the number of hotels for each airport currently reads one. This is because we are carrying information from both nodes and the airport is counting itself as a hotel. We'll need to factor this into our thinking in the next step.

We'll connect a filter tool to the workflow and filter the number of hotels to greater than or equal to 11.

Now the iteration will continue expanding the trade area around each airport until it reaches the count of the 10 hotels and the airport itself. The true output node is information that satisfies our criteria, so we'll connect a macro output tool. We'll call this tool Output and set the anchor abbreviation as O. We're now ready to move onto step two and configure our iteration set of trade areas with fewer than 10 hotels. The false output node contains the dataset that needs to be iterated. However, we want to make sure that we run our iteration on all the airport data available.

To that end, we'll cross reference this dataset with the original incoming airport dataset using a join tool.

That is to say one input of the join must come from the F output node of the filter tool to capture our iteration set while the other must come from the macro input tool to capture the entire airport dataset. We'll join the sets on the IATA field. As usual we only want to bring forward unique data in the output of our join. The columns from the false node of the filter tool or our iteration set duplicate information from the input macro, so we'll deselect them.

We'll also scroll down and ensure that the right IATA has not been renamed. I'll have to erase the new name in my workflow. This is important. If the IATA field going through the macro is not named correctly, the macro won't work. We'll then connect a second macro output to the J node, label it Iteration and set the anchor as I.

Our macro is now almost complete. We're ready to move onto step three and configure the macro in the interface designer. We'll run the workflow, bring up the Interface Designer and go to the Properties tab to specify the tool instructions. The iteration input is the macro input tool while the output is the macro output tool we named iteration.

Next, we need to specify how many times we wish to iterate and what to do when this limit is reached. If our trade areas are too large, they may cease to be useful for business purposes, so we'll limit them to 25 miles. As such, we'll choose 100 iterations and output the leftover records. We're now ready to move onto the final step and test our macro. We'll save the workflow and open a new canvas. We'll bring down an input data tool, and connect the airport locations dataset. We'll then right click on the canvas, select Insert, Macro, and then our iteration macro. We'll add all browsers to the macro and run the workflow.

We'll navigate to the browse connected to the output node and change the map to Carto, Most Recent Vintage. If we look at the results of the output node we can see that 42 airports have at least 10 hotels within the 25 mile radius.

If we look at the map, we can see the radius of our trade areas vary dramatically. Notice that the number of hotels has a minimum of 11 as we would expect but a maximum of higher numbers. This is because the radius is increasing in steps of 0.25 miles, so if that extra quarter mile adds a city center area, it may include many hotels.

Let's now take a moment to run through what we did in this lesson. First, we used a filter tool to separate trade areas that have at least 10 hotels with those that have fewer than 10 hotels. Next, we configured the trade areas with fewer than 10 hotels to run through the macro for another iteration. Third, we configured the macro settings in the Interface Designer. Finally, we tested the macro. This concludes our look at the iterative macro tool. In our next lesson we'll take another look at applications focusing on chaining analytical apps.