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 challenges. For anyone new to the challenges then let us give you an overview how the weekly challenge works. Each Wednesday the Preppin' crew (Jenny, myself or a guest contributor) drop a data set(s) that requires some reshaping and/or cleaning to get it ready for analysis. You can use any tool or language you want to do the reshaping (we build the challenges in Tableau Prep but love seeing different tools being learnt / tried). Share your solution on LinkedIn, Twitter/X, GitHub or the Tableau Forums Fill out our tracker so you can monitor your progress and involvement The following Tuesday we will post a written solution in Tableau Prep (thanks Tom) and a video walkthrough too (thanks Jenny) As with each January for the last few years, we'll set a number of challenges aimed at beginners. This is a great way to learn a number of fundamental data preparation skills or a chance to learn a new tool — New Year...
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 u...
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 ...