2020: Week 33 - Solution

 


This solution is by Tom Prowse and you can download our full solution here

After all the discussions around last week's challenge, this week we took our learning's and applied this to a real-life scenario. This week we want to calculate how many products we are wasting, and how much that's costing us as a result!

Step 1 - Calculate Units Sold

The first step is to join the Daily Sales and Scent tables together. We can do this with an inner join on Scent Code: 


We can do calculate the Units Sold, as we have both Daily Sales and Price within the same table.

Units Sold
[Daily Sales]/[Price]

Step 2 - Calculate Weekly Sales & Units Sold

Now we have our units sold, we can use the Orders table to calculate the weekly groupings. 

First we need to join the Orders table, we can do this with an inner join on Date: 



We then want to remove the Date-1 field, as this will make it easier in the next few steps! After removing the field, we want to do a self-join with our original workflow.


Then this time, we will use the following join conditions:


Using a similar logic to last week, we now want to identify the maximum date for each Date and Scent combination. We can use the following Fixed LOD to do this: 

Week


Now we have identified the Maximum date, we can use a filter to keep only the values that match the date field. Our filter calculation is: 
[Week]=[Date-1]
Now we are working at a weekly level, we can rename our Daily Sales to Weekly Sales. Our data table now looks like this: 


The final step at this stage is to use an aggregation tool to calculate the totals for the week. The aggregation setup looks like this: 


Step 3 - Calculate Waste & Profit

The final step this week is to calculate how much is wasted, and how much that is costing. We can use the following calculations to calculate this: 

Waste
[Units Ordered]-[Units Sold]
Waste Cost
round([Cost]*[Waste],2)

Profit

round([Weekly Sales]-[Waste Cost],2)

Our table now looks like this: 


Now we have calculated the profit metric, all we need to do is use another aggregation to calculate the total profit by Scent.



The final task this week is to rank and tidy the scents according to their profits. First we can use the following calculation to round the Total Profit to 2 decimal places: 

Total Profit
round([Total Profit],2)
Then finally we need to rank the scents using this calculation: 

Profitability Rank



Then we are ready to output the data:



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! 

Popular posts from this blog

2023: Week 1 The Data Source Bank

2023: Week 2 - International Bank Account Numbers

How to...Handle Free Text