2022: Week 18 - Solution
Solution by Tom Prowse and you can download the workflow here.
This week's challenge is focussed on cleaning a pivot table that has a lot of fields (145!!). Although this might be good to look at in a Spreadsheet, it's not the best way of structuring our data in Tableau so let's look at how we can 'un-pivot' our data.
Step 1 - Rename Fields
Now this could be a long manual task as there are 145 fields so it would take a seriously long time for us to go through each one. Luckily, Tableau Prep has a feature that allows us to rename our fields all in one go!
Using the 'Rename Fields' feature we can replace the '___' with a single '-':
This allows us to create the replace the separator between the Type and Date.
We can then repeat this process by replacing '_' with ' ' (space):
At this stage our fields should now all have a similar structure, with the common separator fields throughout:
Step 2 - Pivot Data
The next step is to pivot our data. We want to bring each of the columns into rows so using the columns to rows pivot where we include all of our Type, Date, Measure fields.
As we have so many fields, this could be a problem when trying to select all the fields. Instead of selecting them all, we can use the Wildcard Pivot to dynamically bring all of the fields into the pivot. This is where our separators can come in handy as we use the '-' as our matching pattern:
After the pivot our data should now look like this:
Step 3 - Split Type, Date, & Measure
We can do this by using a custom split, to split all values using the '-' as a separator:
This splits the values into three separate columns that we can rename accordingly, and making sure that we change the Month field to be a date. As a result our table should now look like this: