This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
This article is part of the Tool Mastery Series, a compilation of Knowledge Base contributions to introduce diverse working examples for Designer Tools. Here we’ll delve into uses of the Cross Tab Tool on our way to mastering the Alteryx Designer:
Sometimes you look at the steaming pile of data before you and wonder how you’ll ever get it in the form you need. Every option seems to require a great deal of manual labor, and as a lazy– er that is, as a data blending professional, that is simply something you will not abide.
In situations like these, you may want to consider shaking things up. There's no better tool for this than the Cross Tab, a powerful tool that allows you to reshape your data any-which-way, allowing you to approach your problem from a new angle. In this article, I will demonstrate a few use cases to showcase how you can leverage this awesome tool.
Use Case 1: Extracting dynamic data made easier by assigning groups
You receive a list that looks like Field_1 below. The PMID refers to an ID number for a medical journal article in a database. Each FAU is another author on the paper. There may be any number of authors for a paper.
A table with ID numbers in the first field and columns corresponding to authors.
Prepare the data by filtering and splitting away the identifier. The third column above, "Field_12", shows the usable data.
Use a Multi-Row Formula to identify the ID column and author columns uniquely. In this case, each ID number is represented by ‘0’, and authors are counted up from zero until they hit another ID. See the “Headers” column.
Use another multi-row to associate each group of headers to one another. This is basically a RecordID – it identifies a single paper in the database. See the “Groups” column above.
Cross-Tab! By using these identifying columns, you may shift your data so that each of the Headers creates a column, and each of the Groups create a row. See the confiiguration window in the first image above.
Use Case 2: Performing calculations dynamically for any number of fields
A handful of numerical fields, shown below. They are grouped by a category field and you’ve added a unique RecordID field.
Rolling averages for each column, within their respective category.
Instead of writing a multi-row formula for each column, Transpose everything down to a single column, and tack on the Key Fields “RecordID” and “HP Category”. See the configuration window in the first picture. This results in the below output.
While it may appear to be even more difficult to work with, this allows you to calculate a rolling average in one fell swoop. Use a Multi-Row tool to calculate an Average. You can easily avoid picking up the wrong values by using the Group By option – check off “HP Category” and “Name”. Make sure also to set Values for Rows that don’t Exist to the closest valid row.
Restructure using Cross Tab! (Group by “RecordID”, Header “Name”, Data “r3”)
Use Case 3: Tricky logic made easier with Cross Tab methodologies
You have a list of all possible combinations of 5 items. For each combination, a number of rows corresponding to the number of items lists each item's weight and value - i.e. Combination 123 will be represented three times, with information for item1, item2, and item3.
You wish to optimize your selection of items to meet certain criteria, such as minimum weight and maximum value.
Use a Formulatool to add a column for "Weight" as shown in the first image.
Use the Cross Tab with the "Sum" methodology to find the combined weight of all the items in each combination. The "Weight" header will group all the "kg" values together, and grouping by "Combinations" will create one row for every combination.
Repeat this for "Value" ($).
Pro Tip: Renaming Fields
A downside of the Cross Tab tool is that it doesn't play nice with special characters in field headers, including spaces. This means that if you have a field header "a a", it will actually come out as "a_a". I know this can be a bit inconvenient, but when we were developing the Alteryx engine we prioritized speed and efficiency over keeping the field headers looking nice. Don't worry though - there's a perfectly doable solution to this problem (more than one actually!) that makes use of an awesome tool called Dynamic Rename. This is the way I usually like to go about it:
For the workflows shown in these use cases, please see the supplementary Alteryx package. Note that you may recieve an error upon extracting the content, but this won't affect running the workflow.
By now, you should have expert-level proficiency with the Cross Tab Tool! If you can think of a use case we left out, feel free to use the comments section below! Consider yourself a Tool Master already? Let us know at email@example.com if you’d like your creative tool uses to be featured in the Tool Mastery Series.
Stay tuned with our latest posts every Tool Tuesday by following Alteryx on Twitter! If you want to master all the Designer tools, consider subscribing for email notifications.