2024: Week 15 - Solution



Solution by Tom Prowse and you can download the workflow here.



Step 1 - Days to Removal

First we want to combine both data sets by using an inner join on Product ID: 




This then allows us to calculate the number of days that it took to remove the products. We can calculate this using a datediff calculation: 

Days to Removal 
DATEDIFF('day', #2025-05-13#, [Date])

As a result our table should look like this: 



Step 2 - Recall Targets

Next we want to categories the products to determine whether or not they had met the target. Using an IF calculation we can give each one a category: 

Category
IF [Days to Removal]<=7
THEN 'On Target'
ELSEIF ISNULL([Days to Removal])
THEN 'Incomplete'
ELSE 'Overdue'
END

This allows us to give each of the products a category based on whether they have been removed on time or not.



Step 3 - Output 1 - Store Rank

We can now start to create our outputs. The first one is where we rank our stores based on how long it has taken them to remove the items. 

First, we need to calculate the average removal time per store. For this we can use an aggregation step where we group by Store and calculate the Avg of Days to Removal. 



After the aggregation we can rank the stores based on the avg days to removal across the whole table: 

Rank 


Then finally we can convert the time to days and hours by first duplicating the Days to Removal field, then changing the original Days to Removal to a whole number. This will give us the number of days, then we can use the duplicated field for the hours.

To calculate the hours, we can subtract the days from the days and hours, then multiply by 24: 

Hours to Removal
ROUND(([Hours to Removal]-[Days to Removal])*24)

We can then output our first table that looks like this: 



Step 4 - Output 2 - Overdue & Incomplete

For the second output we want to highlight how many products missed the deadline or are incomplete. For this we want to create a new branch then filter the table so that we exclude the 'On Target' values (or keep the 'Overdue' and 'Incomplete' ones).

Then we calculate the number of days that they are overdue: 

Days Overdue 
DATEDIFF('day', #2025-05-20#, [Date])

After this, we use an aggregation step to calculate the avg days overdue and the quantity for each store: 


Finally we just need to rename the field Days Overdue field to Avg  and round to a whole number.

Avg Days Overdue 
ROUND([Avg Days Overdue])

The final output should look like this: 



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 & @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