2023: Week 29 - Moving Averages

Challenge by: Jenny Martin

Since the 2023.2 version of Prep has been out for a while now, we thought it was high time we played around with a few features! These will be: 

We'll be using them to help AllChains perform a monthly analysis across their Stores. 

One of the key things to watch out for when using a Moving Average is that you have a complete dataset i.e. when you're averaging across 3 months, those 3 months should be consecutive. If not, you're going to want to make sure to scaffold your data, so you have a row for each month, even if there were no sales in that month.

Input

One input this week containing AllChains sales data:

Requirements

  • Input the data
  • We only want to consider complete months so filter values up to June 2023
    • The values after July 2023 are forecasted values
  • Aggregated the data to a monthly level for each Store and Bike Type
  • Notice how not every Bike Type has a sale in every Store each Month (Road bikes in Brixton, for example, didn't have any sales in February 2020). We need to scaffold the data:
    • Use the Lookup function to find the Next Sale Month for each Store and Bike Type
    • You will have nulls for the most recent Month. Replace these nulls with the most recent date in the dataset (June 2023)
    • Use the New Rows step to fill in the missing Months - watch out for duplicate rows!
    • For the months which have been filled in, make sure the value for the Sales and Profit is 0
  • Calculate the 3 month Moving Average for the Profit for each Store and Bike Type
  • Output the data, naming the file dynamically with the Month and Year in which the file was fun
    • e.g. July 2023 Analysis

Output


  • 6 fields
    • Month
    • Store
    • Bike Type
    • Sales
    • Profit
    • 3 Month Moving Average Profit
  • 2,089 rows (2,090 including headers)
You can download the output from here.

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