2022: Week 1 - Solution
Solution by Tom Prowse and you can download the workflow here.
Step 1 - Input Data
Step 2 - Pupil's Name
Notice that we can also include other pieces of text, and these are shown by using inverted commas / speech marks.
As a result of this calculation our table now looks like this (the fields that we have used are in the red box:
Step 3 - Parent Contact Name
The first part of the calculation just returns the last name for each pupil (for this challenge we are assuming that the children and parents have the same name), then we separate with a comma just like in the previous pupil name calculation.
The second part of the calculation is the IF statement where we make a decision on what parent to take depending on the Parental Contact field (Parent 1 or Parent 2).
As a result of this calculation our data should now look like this:
Step 4 - Contact Email
This uses the same IF statement as before, but then adds in a '.', the last name, an '@' symbol, the parents company, and finally a '.com'. Each of the pieces of text that are the same throughout the rows are added between inverted commas to ensure that Tableau Prep recognises them as text.
Our table should now look like this:
Step 5 - Academic Year
The next step takes us away from the String calculation theme that has been running through the previous steps. For this step we need to focus on Date calculations instead as we want to calculate what academic year each of our pupils is in based on their date of birth.
Within the requirements we are told that each academic year starts on 1st September and that pupils born after 1st Sept 2014 are in academic year 1. Therefore we can use the following calculation to categorise each public into a year:
Academic Year
ELSEIF [Date of Birth] >= #2013-09-01# THEN 2
ELSEIF [Date of Birth] >= #2012-09-01# THEN 3
ELSEIF [Date of Birth] >= #2011-09-01# THEN 4
END
For each row we have determined whether the Date of Birth field is greater than or equal to (>=) the given date (this is shown between the #'s). We have then done this for each of the different years up to year 4.
This probably isn't the best way forwards as you would need to update this calculation every year for the new students, but at this stage we are happy with this calculation.
The table of data should now look like this:
Step 6 - Tidy for Output
- Three Dots then Remove
- Select multiple fields (using CTRL/CMD key) and then pressing Keep Only or Remove Fields
We have decided the go for the Keep Only option, therefore we need to highlight the four fields that we want to keep (Academic Year, Pupil's Name, Parental Contact Full Name, and Parental Contact Email Address) then press the Keep Only button.
Congratulations 🎉 We have finished the first #PreppinData of the year!!
Our output should look like this: