2021: Week 32 Excelling through aggregation

 Challenge by: Carl Allchin

My partner is an amazing Excel user as are many of her colleagues. When in a pub, a frequent getting to know you question was "What's your favourite Excel function?". As a SQL / Tableau user, after my first meeting I knew I had to up my game. SUMIFS became my go to answer and that is one of the functions we will look to replicate in Prep this week. 

SUMIF, or SUMIFS if you have multiple conditions, allows you to scan a data set and summarise the values that match any condition you create. When working with large tables with multiple entries per category, this is a great way to create some totals to help you analyse the data set. Whilst SUMIF doesn't exist within Prep, the IF function and aggregation step can be used to create the same effect. 

Excel allows for lots of different types of aggregations so whilst SUMIF was my go-to answer: average, minimum, count etc are all possible too. 

The challenge this week is forming the logic in Prep to replicate SUMIFS and AVERAGEIFS.

Input

Daily ticket sales for each flight for six months.


Requirements

  • Input data
  • Form Flight name
  • Workout how many days between the sale and the flight departing
  • Classify daily sales of a flight as:
    • Less than 7 days before departure
    • 7 or more days before departure
  • Mimic the SUMIFS and AverageIFS functions by aggregating the previous requirements fields by each Flight and Class
  • Round all data to zero decimal places
  • Output the data

Output


One file containing:
6 data fields:
  • Flight
  • Class
  • Avg. daily sales 7 days of more until the flight
  • Avg. daily sales less than 7 days until the flight
  • Sales 7 days of more until the flight
  • Sales less than 7 days until the flight

The full output can be found 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