Alteryx Macros Example 2 - Finding Number of Columns for Text to Columns Tool - Part 1

by Liu Zhang

Macro is a very useful part of Alteryx, as it is a custom build tool to perform tasks. There are a few examples already from the Data School cohorts available. (Link: 1, 2, 3)

While trying to study for Alteryx Designer Advanced Certification, I find that I needed to know much more about various Interface tools, a simple macro example is not sufficient, so I would like to share more complicated examples for people want to know about them and my thought on design process.


This series will concentrate on the use of Text to Columns tool.

Text to Columns

As the name suggest, the tool is a very useful way of parsing data (without using RegEx), but there are cases where we don't know how many columns do we need to split the original input data. We could guess/try a large number and find the answer or we could split to rows.

This may not be the most efficient way when data set is large or try to find the correct setting to pivot back. So this is a process can be done through a macro to standardize the steps.

A dummy input column

Text to Columns requires us to specify which delimiter(s) to be used and for Split to columns, we need to specify how many columns are needed. Those two pieces of information are the ones we would like to control and change.

Note: for the demonstration purpose, we will / as the single delimiter for the setup.

Tool configuration

Once we decided which delimiter to use, then we need to figure out how many of them are within the input data, we can use that to deduce how many columns will be needed.

Use a Formula Tool for calculation

In practice, we are likely to have multiple rows of data, so to make sure we have enough columns for all of them, we will choose the max number of delimiter count with a Summarize tool.

Find max count
Workflow

This is the first issue I encountered when building the workflow, as the Summarize input cannot be directly inputted to update Text to Columns tool within the same workflow, this is where the idea of Nested Marco comes in and we will discuss that in Part 2 of the series.

Note: We will continue by assuming 3 columns (default) to split.

So let's first deal with change of delimiter in the macro. To allow users some customization in using the tool, we can attach a Text Box from Interface tool to allow the user to choose which delimiter they want to use.

Text Box
Tool configuration

Text box is a very simple tool to configure, we can leave the default setting (just changing the interface text). All the interface tools has a Q(uestion) icon at the bottom of the tool and we connect them to the lighting(action) icon, an Action tool will always be connected in between automatically.

Note: Sometimes it is possible to connect directly from Q to Q between two tools, but it is recommended to use Action tool for detailed configuration and debug.

Workflow

For both Formula and Text to Columns tool, we would like to update the / in the initial tool that we had inputted when setting up the workflow. Remember to select the last option to update the value.

Update Formula Tool
Update Text to Columns Tool

We can save the macro and test it. All the workflow are packaged into a single icon.

Custom icon can be customized

Let's test with an example input

Sample input
Choose the column and the delimiter
Output

We can see the macro can calculate three / exists in input data, where the result columns are in 1, 2, 3. Notice the last column also has / in it, as the default Text to Columns tools is 3, so it did not split it despite the existence of delimiter.

In the next part of the series, we will see how we can incorporate the calculated delimiter count into the macro to improve it.


Looking for more guides, tips and tricks in Tableau or Alteryx? Go check out the other blog posts from the Data School.

Tableau Public

LinkedIn

Twitter

Tue 14 Dec 2021

Sun 03 Oct 2021

Tue 28 Sep 2021