Whether I’m exploring personal or work-related data, I frequently use a technique that I call “creating Tableau Buckets”.
Whenever I have to group items together in some fashion, I usually just create a bucket with a calculated field. I have written a few blog posts about different types of buckets in the past, but this weekend I created a new type of bucket that you might find useful. I call this the “Weekend vs Weekday” bucket. As you might guess from the name of the bucket, this will place data that occurred on Sat/Sun in the “Weekend” bucket and Mon-Fri data in the “Weekday” bucket. This is accomplished with a simple formulation that is shown below, followed by a short video showing its usage.
If you like this article and would like to see more of what I write, please subscribe to my blog by taking 5 seconds to enter your email address below. It is free and it motivates me to continue writing, so thanks!
Given any data that has a date field connected to it, you can place the data into the “Weekend or Weekday” bucket by using this formula:
// Weekend or Weekday Bucket, Ken Black, November 18, 2013 // This bucket is used to aggregate items based on the day of the week. // If the item occurred on Sat/Sun, it goes into the Weekend bucket. // If the item occurred on Mon-Fri, it goes into the Weekday bucket. // // Simple and clean if then else structure using Datepart command. // if(DATEPart('weekday',[Date])=1) then 'Weekend' //Sunday elseif(DATEPart('weekday',[Date])=2) then 'Weekday' //Monday elseif(DATEPart('weekday',[Date])=3) then 'Weekday' //Tuesday elseif(DATEPart('weekday',[Date])=4) then 'Weekday' //Wednesday elseif(DATEPart('weekday',[Date])=5) then 'Weekday' //Thursday elseif(DATEPart('weekday',[Date])=6) then 'Weekday' //Friday elseif(DATEPart('weekday',[Date])=7) then 'Weekend' //Saturday end
Video 1 shows how you can create this type of bucket. Originally I created this post with information on why I needed this bucket. I completed the article, published it, only to find out that WordPress somehow saved an earlier version, rather than the final post. I’ll take that as a message to stop the post now. I’m not going to bore you with the details of why I needed this bucket, but suffice it to say that it is useful if you want to compare what happens during the week to what happens during the weekends.