Introduction

This tutorial is a continuation on the previous posts on the various types of macros in Alteryx, as well as, creating standard macros in Alteryx.

This time we will move on to batch macros. To recap, a batch macro in Alteryx allows you to run a workflow multiple times, processing different subsets of data each time. In this tutorial, we will use the same YouTube data from last time, but we will automate the process of calculating the engagement ratios (likes + dislikes per view) for each category.

Step 1: Download the Dataset

Download the dataset from this link. If you followed the previous tutorial on Standard Macros, you may recall the data is separated into different years. Instead of loading each year individually, our Batch Macro will process them dynamically. Save them all in a single directory.

Step 2: Prepare the Data Extraction

Drag a Directory Input tool onto the canvas and set it up to point to the location of the downloaded files.

Use the Select tool to select the FullPath and FileName. Rename FileName to Year.

Use the Data Cleansing tool to remove letters and punctuation from the Year column, leaving just the year.

Now using the Filter tool select the Basic filter option and set the condition to Year = 2005.

Following this, the Dynamic Input tool is connected. Two three options need to be set:

  1. Input Data Source Template – this needs to be pointed at one of the youtube csv files to serve as a template.
  2. Read a List of Data Sources – change the field to FullPath.
  3. Action – set this to Change Entire File Path.

Step 3: Select the Fields and Convert Data Types

Use the Data Cleansing tool to remove the punctuation from the Video views, Likes, and Dislikes columns.

Use the select tool to select the previously mentioned fields. Additionally, change the datatypes for Video views, Likes, and Dislikes to Double.

Use the Summarize tool to sum all the likes, dislikes, views for each category as follows:

Step 4: Calculate Engagement Ratio for each Category

Use the Formula tool to create a new field called “Engagement Ratio”. The calculation will be:

([Total Category Likes] + [Total Category Dislikes]) / [Total Category Views]

Optionally, sort the Engagement Ratio field to see the best performers using the sort tool. The workflow should look similar to the following.

Step 5: Convert Workflow into a Batch Macro

Now add a Control Parameter tool. This parameter will take a list of years that we want to load later. Connect the output Q to the lightening bolt on the Year filter.

As can be seen above, the Action tool is automatically inserted between the Control Parameter tool and the Filter tool. Select Action tool and set the action type to Update value and select the Operand – value = ‘2005’ as the value to update.

Right click on the Browse tool and convert it to a Macro output.

If these steps have been successful, the Workflow configuration Type should now be Batch Macro.

Created with GIMP

Save the macro as BatchEngagementMacro.yxmc.

Step 6: Use the Macro in a New Workflow

Open a new workflow and add a Text Input Tool to the canvas. Setup one column named Year with some year values to test.

Add a Select tool and change the Year data type to string to match the macro.

Now right-click on the canvas and select Insert –> Macro and then select the newly created BatchEngagementMacro and connect it to the Select tool.

Run the workflow and discover which category had the highest engagement ratios for each year.

Conclusion

In this tutorial we worked through the process of creating a batch macro in Alteryx. Additionally, we used the macro in a new workflow to test its functionality. In the next post we work through the process of creating and using iterative macros.

Troy
Author: Troy

Troy holds degrees in Science, IT, and Education. These have equipped him with a multidisciplinary foundation combining analytical thinking, problem-solving, and technical proficiency. During his graduate studies at CSIRO, where he analysed genetic sequence data and gene expression profiles as part of a broader research project, he developed a deep interest in uncovering insights through data. After several years as a STEM educator, Troy has transitioned back to being data-focused, bringing a unique perspective shaped by his teaching experience and ability to convey complex ideas effectively. His skills cover the entire data lifecycle, from data cleaning and analysis to creating effective visualisations that support decision-making. In his free time, Troy enjoys trail running and staying active, relishing the chance to clear his mind and explore the outdoors.