2020: Week 39 - Solution
Solution by Tom Prowse and you can download our solution here.
This week we took a deeper look at Jonathan's latest viz which focussed on Pret a Manger's new deal in the UK. However, we have some slightly more complex orders therefore we will use Tableau Prep to take a deeper look to see if the deal is worth while.Step 1 - Restructure Orders
First we are going to focus on the Orders input, and restructuring the table so that we have a line for order for each person. Therefore the first step is to use a Pivot tool to bring each of the day's into a single column:
After the pivot our table looks like this:
Step 2 - Restructure Price List
Next we are going to focus on the Price List input with a similar process to the orders table.
Again, we first want to pivot the data but this time we need to pivot two values compared to just one. Therefore the first pivot values can be a wildcard on 'Price' and then the second pivot values can be the remaining fields. The setup will look like this:
After the pivot we want to remove any null values from the Pivot 2 Values field, and then remove the word 'Price' from the Pivot Names. There are multiple ways of doing this but we have used a custom split:
Note: You may need to trim some spaces as a result of the split.
The last part of this step is to rename some fields and our table should now look like this:
Step 3 - Join Orders to Drinks
After this calculation we are left with a nice clean table that looks like this:
We can now join this back to our first branch, using an Inner Join on Order Split = Category Split:
The last step is to remove any fields that don't match up. To do this we can use a Contains calculation:
CONTAINS([Order],[Drink])
Using this within a filter will mean we only keep the rows where the Order is within the Drink string.
Finally, we want to bring all of the fields back together from both of the joins. Therefore we can use a union tool to stack these on top of one another, and our workflow looks like this:
After removing any unwanted fields our table now looks like this:
Step 4 - Is the Deal Worth it?
This is the final part of this week's challenge and is where we see if the deal is worth it for each person. First, we need to calculate how much each person has spent on each drink per month. We calculate this by:
Spend
([Frequency]*[Price])*4
*Multiply by 4 as that's how many weeks in the month
We then use an aggregation tool to calculate the total spend per person:
Potential Savings
After this calculation then this is the challenge completed for this week with this output:
After you finish the challenge make sure to fill in the participation tracker, then share your solution on Twitter using #PreppinData and tagging @Datajedininja, @JennyMartinDS14, @JonathanAllenby & @TomProwse1
You can also post your solution on the Tableau Forum where we have a Preppin' Data community page. Post your solutions and ask questions if you need any help!