2021: Week 2 - Solution
Solution by Tom Prowse and you can download the workflow here.
It's week 2 of the 2021 Preppin' Data challenges and we are continuing on our fundamentals journey by focusing on Aggregating and Calculations.
Again we were looking at Bike sales data and wanted to create some quick summaries to answer questions related to brand and store performance.
Step 1 - Create Brand Field
The first step this week is to clean the Model field so that we only have the letters for each brand.
The first step is to duplicate the Model field. We do this because we want both Model and Brand within our dataset so can't just clean the Model field without first duplicating it. This can be achieved by Right-Clicking and choosing Duplicate Field.
Once duplicated, we can use the Clean functionality within Tableau Prep to remove letters and punctuation. The Clean functions can be found by pressing the three dots, then selecting Clean:
Now we have cleaned the Model field to create our Brand field the table looks like this:
Step 2 - Calculate Order Value
The next step is to create the Order Value for each brand. This calculation involves multiplying Quantity and Value per Bike together using the following syntax:
Order Value
[Quantity]*[Value per Bike]
As a result we now have a new field that containing our Order Value:
Step 3 - Aggregate Brand & Type
For our first aggregate and output we need to have our Value per Bike, Order Value and Quantity by Brand and Type.
This means that we need to:
Group By
- Brand
- Type
Aggregate
- Sum Order Value
- Sum Quantity (rename to Quantity Sold)
- Avg Value per Bike (rename to Avg Bike Value per Brand, Type)
The setup within the Aggregate tool looks like this:
After the aggregation our table now looks like this:
Step 4 - Round Values
Step 5 - Days to Ship Calculation
Step 6 - Aggregate Brand & Store
The next aggregation that we need to do involves the following:
Group By
- Brand
- Store
Aggregate
- Sum Order Value (rename to Total Order Value)
- Sum Quantity (rename to Total Quantity Sold)
- Avg Days to Ship (rename to Avg Days to Ship)
The aggregation tool setup looks like this:
After the aggregation our date now looks like this:
Step 7 - Round Avg Days to Ship
The final step this week is to round the Avg Days to Ship value to 1 decimal place. We are going to use a similar calculation as before:
Avg Days to Ship
ROUND([Avg Days to Ship],1)
We are then ready to output our second table:
Sales by Brand and Store