Alteryx's batch macros allow you to process multiple inputs or files simultaneously. This automation is beneficial when dealing with large datasets or repetitive tasks.
Batch macros take a list of inputs as an input parameter and use that list to iterate through a workflow, performing the same actions on each input file or record.
It can help simplify and streamline data processing from multiple sources, such as cleaning, transforming, or summarizing.
Batch macros are a valuable tool for automating repetitive data processing tasks, saving time and effort when working with large datasets.
Some use cases for Batch macros:
- Data preparation: If you need to clean, transform, or summarize data from multiple sources, a batch macro can help you perform these tasks more efficiently. You can use a batch macro to apply the same set of operations to each input file or record, reducing the manual effort required.
- Reporting: Batch macros can generate reports for multiple inputs, such as creating summary reports for each department in a company. Using a batch macro, you can develop these reports automatically and save time and effort.
- Data integration: If you need to combine data from multiple sources into a single dataset, a batch macro can help you do this more efficiently. You can use a batch macro to read various input files, merge or join them together, and output a single dataset that combines all of the inputs.
- Quality control: Batch macros can perform quality control checks on multiple inputs, such as missing values or outliers. Using a batch macro, you can apply the same set of checks to each input and quickly identify any issues that need addressing.
There are different types of Macros in Alteryx; Standard Macros, Batch Macros, and Iterative Macros. But, distinctively from others types, we use a tool that is only dedicated to batch macros called the Control Parameter tool.
An example of the Batch Macro is the following:
This webscrapping workflow obtains the name of the team and the number of home runs per team in the year 2022. When we run it, we will see information about the 30 teams in the MLB, the number of total home runs per team, and the year.
Now, if we want to obtain the number of home runs for the last three years, you will have to create three different flows such as this:
Let's say you want to do the last 20 years. You'll have to create 20 different flows, which is overwhelming. This can become a lot if we want to obtain more years.
To make this more efficient, we can create a Batch Macro.
First, you’ll copy and paste the workflow into a new sheet, add the control parameter and convert the output file into an output macro. And we will connect the Control Parameter to the text input tool containing the URL.
After we connect the control parameter tool, it will automatically create an action tool. The action tool performs the action we want it to do for the text input. We will also connect the parameter to the year of the data set input text tool, since I want to append the year next to the data. In this case, we want to change the year.
We will now set up the Control Parameter. We will click on the Control parameter tool, and rename it. Then you’ll click on the Action tool, and for “Select an Action type,” we choose Update value. Under Value or Attribute to update> we will click on text input →Data→r→ Double click on that given option. We will then tick the check box that says “Replace a specific string,” We will erase everything except for 2022, which is part of the string I want to change.
Now that we have set up the Control Parameter, we have one more step to do for this macro: turn the output file into a Macro Out. You can replace your output tool at the end of the flow with a Macro Output from the interface tool palate.
Now that we have set up the macro make sure to save it.
We will now open a new sheet. We will drag a text input tool, write years as a header, and input all the years we want to see. In this case, we will put 2022, 2021, and 2020.
We will then drop the newly created Macro into the canvas, connect to the text input tool, and add a browse tool at the end to check the results.
After running the workflow, we see that we have successfully obtained the data for 2020-2022.
Once we inspect the browse tool, we see we have 30 rows of data for each year, which we wanted to see.
Overall, batch macros are a versatile tool that can help you automate many different types of data processing tasks, saving you time and effort and improving the quality of your work.