2021: Week 26 Rolling Weekly Revenue

Challenge by: Carl Allchin

For any analyst, you are likely to get asked to use some complex calculations. For me, rolling or moving calculations are one that I've always preferred to do in the data preparation step rather than when trying to visualise the data if possible. It's saved me from some mistakes! 

This week's challenge is looking at creating moving calculations. By this let's use the example below, where on 5th January (yes British date format), if we wanted to understand a rolling week's values, you can include 3 days before the 5th (ie the 2nd, 3rd and 4th) as well as 3 days after the 5th (ie the 6th, 7th and 8th). 


Clearly you need to define what your rolling period should include or not. A rolling week could look backwards for 6 days inclusive of the current date or 7 days if you don't use the current date. You could look the same period forward but ultimately you have to articulate what you are covering to your audience. The nature of the data might also influence the decision you are taking. 

Challenge

Create a rolling weekly total and average for each Prep Air destination and an overall number for all destinations. The rolling week is as detailed above, 3 days before and 3 days after a date as well as that day itself. 

Input




Requirements

  • Input data
  • Create a data set that gives 7 rows per date (unless those dates aren't included in the data set). 
    • ie 1st Jan only has 4 rows of data (1st, 2nd, 3rd & 4th)
  • Remove any additional fields you don't need 
  • Create the Rolling Week Total and Rolling Week Average per destination
    • Records that have less than 7 days data should remain included in the output
  • Create the Rolling Week Total and Rolling Week Average for the whole data set
  • Pull the data together for the previous two requirements
  • Output the data

Output


One table:

Four data fields:
  • Destination
  • Date
  • Rolling Week Avg
  • Rolling Week Total
360 rows (361 including headers)

Here's our full output for comparison. Remember we don't care about the order of the columns or rows as Tableau Desktop will import them in whatever order they come in!

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

2024: Week 1 - Prep Air's Flow Card

2023: Week 1 The Data Source Bank

How to...Handle Free Text