This week we looked at the classic question, that can be a bit tricky in Tableau, about how to calculate working days. Working days traditionally exclude any weekends and bank holidays and are used in various business reports, especially with anything around productivity and scheduling.
For this challenge we wanted you to take a custom start date and work out how many working days it has been since that date. In the original challenge post, Jenny had selected a start date as 1st April 2019, so we'll continue with that date in this solution post as it was the date I started at The Information Lab as well!
Step 1 - How Many Days?
The first step is to calculate how many days there have been since your selected start date. For this we will create a 'Today' field to use as our end date (this can be any date that you want to use).
Today
Today()
Now we have a start and end date, we can calculate how many days are between the two:
How Many Days?
DATEDIFF('day',[Start Date],[Today])
We should now have the following three fields:
Step 2 - Fill in Dates
The next step is to create a row for each of the different dates between the start and end date. To do this we are going to use the scaffold table and join this to our original workflow. We use the following join conditions:
This has now created a running sequence from the start to end date, and this can then be used to calculate how many days there have been. To transfer the scaffold into the actual date, we use the following calculation:
Days Between
DATE(DATEADD('day',[Scaffold],[Start Date]))
We now have a row for each of the dates between our start and end date:
As with the definition of working days, we want to remove all of the weekends from our list of dates. To do this, we can calculate the weekday of each of the dates using this calculation:
Weekday
DATENAME('weekday',[Day Between])
We can then select 'Saturday' and 'Sunday' from our Weekday list and exclude them from our table.
We also want to remove any bank holidays from the list of dates. For this we will bring in the UK bank holidays table, and join to our original workflow. For this join we are completing an Outer Left Join where Day Between = UK Bank Holidays:
We use an Outer Left Join here as we want to include all of the fields from the left table (original workflow) but then want to exclude all of the values that match the right table (bank holidays). This join then acts as a filter and removes all of the bank holidays which we don't need!
The final task is to calculate how many days there have been once we have excluded both bank holidays and weekends, meaning we want to count how many rows we have left.
Using an aggregate tool we can Group By Start Date & Today, then Count Distinct the Day Between field:
We now have a single row of data - Start Date, End Date (Today), & Day Between (Working Days):
Step 3 - Remove Holidays
The final step this week is to remove any additional holiday days that we have taken off. We need to input the Holidays table, then use an aggregation to calculate the total days taken. Within the aggregation we don't want to group by anything, and want to Sum the Holidays field:
After totalling, we want to join this onto our original workflow. As we currently don't have any common fields in which to join, we need to create a dummy join field. This can be anything, but in our case we have chosen a '1'.
We need to create the join field on both the holidays branch and the original workflow, then use this within the join condition:
After the join our table now looks like this:
We can now subtract the number of holidays from our Day Between field and that gives us the total working days:
Working Days
[Day Between]-[Holidays]
This is the final step, then we can clean the file and ready this for our Output:
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!
Created by: Carl Allchin Welcome to a New Year of Preppin' Data. These are weekly exercises to help you learn and develop data preparation skills. We publish the challenges on a Wednesday and share a solution the following Tuesday. You can take the challenges whenever you want and we love to see your solutions. With data preparation, there is never just one way to complete the tasks so sharing your solutions will help others learn too. Share on Twitter, LinkedIn, the Tableau Forums or wherever you want to too. Tag Jenny Martin, Tom Prowse or myself or just use the #PreppinData to share your solutions. The challenges are designed for learning Tableau Prep but we have a broad community who complete the challenges in R, Python, SQL, DBT, EasyMorph and many other tools. We love seeing people learn new tools so feel free to use whatever tools you want to complete the challenges. A New Year means we start afresh so January's challenges will be focused on beginners. We will use dif
Challenge By: Jenny Martin For week 2 of our beginner month, Data Source Bank has a requirement to construct International Bank Account Numbers (IBANs), even for Transactions taking place in the UK. We have all the information in separate fields, we just need to put it altogether in the following order: Inputs A list of the transactions, with information about the receiving bank account A lookup table for the SWIFT Bank Codes Requirements Input the data In the Transactions table, there is a Sort Code field which contains dashes. We need to remove these so just have a 6 digit string ( hint ) Use the SWIFT Bank Code lookup table to bring in additional information about the SWIFT code and Check Digits of the receiving bank account ( hint ) Add a field for the Country Code ( hint ) Hint: all these transactions take place in the UK so the Country Code should be GB Create the IBAN as above ( hint ) Hint: watch out for trying to combine sting fields with numeric fields - check data types Re
Free isn't always a good thing. In data, Free text is the example to state when proving that statements correct. However, lots of benefit can be gained from understanding data that has been entered in Free Text fields. What do we mean by Free Text? Free Text is the string based data that comes from allowing people to type answers in to systems and forms. The resulting data is normally stored within one column, with one answer per cell. As Free Text means the answer could be anything, this is what you get - absolutely anything. From expletives to slang, the words you will find in the data may be a challenge to interpret but the text is the closest way to collect the voice of your customer / employee. The Free Text field is likely to contain long, rambling sentences that can simply be analysed. If you count these fields, you are likely to have one of each entry each. Therefore, simply counting the entries will not provide anything meaningful to your analysis. The value is in