Questions from Tableau Training: Business Day Calculations

Data

Questions from Tableau Training: Business Day Calculations

by Jon Bajon
//

Our Certified Tableau Trainers are asked a myriad of questions each day. In this series, they share some answers.

A common question that often comes up in trainings is:

“How do I run a ‘difference between two dates’ calculation only considering business days?”

In order to focus on business days, we need to adjust our calculated field to define what a “Business Day” is. First, we need to be aware that Tableau gives each weekday a numerical value shown in the table below:

Weekday numerical value

The first calculation checks to see how many weeks have passed between the start date and the end date. That result is multiplied by 5 (represented by 5 business days in a week) to assign the total number of business days that have passed. For example if a product takes 3 ½ weeks to manufacture, this calculation would return 15. We need keep in mind this number sequence when creating our calculated field so that we can remove Saturday and Sunday. The calculation can be done in one step, but it is much easier to talk about each part individually.

How Many Weeks?

The next calculation returns the minimum value between numerical value (remember the table?) of the weekday of the end date and 6. Why 6? Think of this step as checking to see if the weekday is somewhere between Sunday (1) and Friday (6). This takes care of removing Saturday from our calculation. For example if a product ships on Tuesday, the value returned is the minimum of 2 and 6, which would be 2.

Weekday Check for Ship Date

Lastly, we need to make the same calculation as above but this time for our start date.

Weekday Check for Order Date

Now to combine them all together! (You can reference the smaller calculations or write it all in one.)

The first calculation that determines the number of weeks will be our base. We can then add the second calculation, which returns the number of the weekday and overshoots the actual value. We need to correct for this by subtracting off the third calculation (return of the number value for the end date).

Combined Tableau calculation

OR

A simple example would be:

Start Date                           End Date

Oct. 2, 2015                       Oct. 26, 2015

 

DATEDIFF( ‘week’, Oct. 2, 2015, Oct. 26, 2015)* 5 =  15

+

MIN(DATEPART(‘weekday’, Oct. 26, 2015) ,6) = 5

MIN(DATEPART(‘weekday’, Oct. 2, 2015) ,6) = 2

 

Total Business Days  =  18

 

In the example below, we can compare our business day calculation with the date difference calculation (DATEDIFF( ‘day’, [Order Date], [Ship Date])) and see that the weekends are not included.

 

Comparing Tableau calculations

Note: This does not include the first day in the calculation. Wrapping the entire calculation in () and adding 1 would correct this.

When you use your new field in the view, remember to pay attention to the aggregation Tableau uses and make sure it is set to how you want to view your data. Using Tableau’s default sum function will combine rows with the same date values and may give a much larger number than expected, whereas forcing the calculations to have the attribute function will ensure that they are computed at a row / transactional level – as used in the calculation above.

Want More Questions from Tableau Training

  1. Questions from Tableau Training: Quick Filter Interaction
  2. Questions from Tableau Training: Labeling with Table Calculations
  3. Questions from Tableau Training: Speeding Up Presentation Views when Using Tableau
  4. Questions from Tableau Training: Dashboard Actions
  5. Questions from Tableau Training: Business Day Calculations
  6. Questions from Tableau Training: Adding Gaps Between Bars
  7. Questions from Tableau Training: When to Pivot Data in Tableau
  8. Questions from Tableau Training: Adding Conditional Formatting
  9. Questions from Tableau Training: Setting Weekday Start
  10. Questions from Tableau Training: How Do ZIP Codes Work in Tableau?
  11. Questions from Tableau Training: The Small Grey Bar Within a Quick Filter
  12. Questions from Tableau Training: Matching Mark Color
  13. Questions from Tableau Training: Showing the Null Indicator
  14. Questions from Tableau Training: Can I Manually Set the Colors of a Stepped Gradient?
  15. Questions from Tableau Training: How Can I Get Box Plot Data into a Crosstab?
  16. Questions from Tableau Training: How Do I Clear a Worksheet? Make a Copy?
  17. Questions from Tableau Training: Opening URL Actions Inside of a Dashboard
  18. Questions from Tableau Training: Can I Move Mark Labels?
  19. Questions from Tableau Training: How Can I Use My Current Report to Create a Viz?
  20. Questions from Tableau Training: Can I Create Text Hyperlinks on a Dashboard?
  21. Questions from Tableau Training: How Can I Transform My Crosstab into a Flat List?
  22. Questions from Tableau Training: Labeling the Top N
  23. Questions from Tableau Training: How Can I Customize Charts with Parameters?
  24. Questions from Tableau Training: Combining Measures into a Single Line
  25. Questions from Tableau Training: How Can I Create Custom Color Palettes?
  26. Questions from Tableau Training: Can a Top N Parameter be Nested Within Other Fields?
  27. Questions from Tableau Training: Conditional Scope on Tableau Calculations
  28. Questions from Tableau Training: Top Ten Plus N
  29. Questions from Tableau Training: Dynamic Label Positioning
  30. Questions from Tableau Training: Using Cross Joins to Solve Active Tickets
  31. Questions from Tableau Training: Top N Highlight Table
  32. Questions from Tableau Training: How to Use Specific Dimensions in Table Calculations
  33. Questions from Tableau Training: Moving Reference Line Labels
  34. Questions from Training: Comparing Metrics for Same Weekday in Previous Year
  35. Questions from Tableau Training: Colouring Specific Columns and Rows in a Crosstab
  36. Questions from Tableau Training: Creating a Custom Legend as a Sheet
  37. Questions from Tableau Training: How Can I Draw a 45-Degree Angle?
  38. Questions from Tableau Training: Down the Aggregation Rabbit Hole
  39. Questions from Tableau Training: Percent Change from Previous Period on a Map
  40. Questions from Tableau Training: Union File Names as Years
  41. Questions from Tableau Training: Conditional Coloring on Sparklines
  42. Questions from Tableau Training: Moving Column Headers to the Top of the View
  43. Questions from Tableau Training: Isolating Rank with Parameters and Calculations

More About the Author

Jon Bajon

Analytics Consultant
Tableau Viz: How Much Heat Can You Handle? It might sound controversial, but a common practice in my family (and many families throughout Louisiana) was something called ...
Questions from Tableau Training: Can a Top N Parameter be Nested Within Other Fields? The latest question from Tableau Training comes from Ryan, who was in a DII: Intermediate course in New York City. “I know I can ...

See more from this author →

InterWorks uses cookies to allow us to better understand how the site is used. By continuing to use this site, you consent to this policy. Review Policy OK

×

Interworks GmbH
Ratinger Straße 9
40213 Düsseldorf
Germany
Geschäftsführer: Mel Stephenson

Kontaktaufnahme: markus@interworks.eu
Telefon: +49 (0)211 5408 5301

Amtsgericht Düsseldorf HRB 79752
UstldNr: DE 313 353 072

×

Love our blog? You should see our emails. Sign up for our newsletter!