Tableau Calculated Field Show Weekdays Without Holidays
This guide explains how to create a Tableau calculated field that shows only weekdays (Monday through Friday) while excluding holidays. This is useful for business analytics, project planning, and any scenario where you need to exclude weekends and holidays from your date calculations.
Introduction
In Tableau, calculated fields allow you to create custom calculations based on your data. One common requirement is to filter dates to show only weekdays (Monday-Friday) while excluding weekends and holidays. This guide will walk you through creating such a calculated field in Tableau.
Why would you need this? Imagine you're analyzing sales data and want to exclude weekends and holidays when calculating average daily sales. Or perhaps you're tracking project milestones and need to exclude non-working days from your timeline calculations.
How to Create the Calculated Field
- Open your Tableau workbook and connect to your data source.
- Right-click on the date field you want to filter in the Data pane.
- Select "Create" > "Calculated Field".
- In the Calculated Field dialog box, name your field something descriptive like "Weekdays Without Holidays".
- Enter the formula (we'll explain this in detail in the next section).
- Click OK to create the calculated field.
- Drag the new calculated field to the Filters shelf.
- Select "True" to filter your data to show only weekdays without holidays.
Formula Explanation
The formula for this calculated field combines two checks:
// Check if the date is a weekday (Monday-Friday)
// AND if it's not a holiday
IF (WEEKDAY([Date Field]) < 6) AND NOT (ISDATE([Date Field], [Holiday List])) THEN TRUE ELSE FALSE END
Let's break this down:
- The WEEKDAY function returns a number (1-7) representing the day of the week, where 1 is Sunday and 7 is Saturday.
- We check if the weekday is less than 6, which means Monday (1) through Friday (5).
- The ISDATE function checks if the date exists in a list of holidays.
- We use NOT to exclude holidays from our weekday check.
- The final IF statement returns TRUE for dates that are weekdays and not holidays, FALSE otherwise.
Note: You'll need to create a separate data source or parameter containing your list of holidays for this formula to work.
Example
Let's say you have a sales dataset with dates from January 1, 2023 to January 31, 2023. Your holidays for this period are January 1 (New Year's Day) and January 16 (Martin Luther King Jr. Day).
Using our calculated field, Tableau would:
- Show all Monday-Friday dates in January 2023
- Exclude weekends (Saturday and Sunday)
- Exclude January 1 and January 16 (your holidays)
This would give you 20 working days in January 2023 (23 total days minus 3 weekends minus 2 holidays).
| Date | Day | Is Holiday? | Included in Calculation? |
|---|---|---|---|
| 2023-01-01 | Sunday | Yes | No |
| 2023-01-02 | Monday | No | Yes |
| 2023-01-03 | Tuesday | No | Yes |
| 2023-01-04 | Wednesday | No | Yes |
| 2023-01-05 | Thursday | No | Yes |
| 2023-01-06 | Friday | No | Yes |
| 2023-01-07 | Saturday | No | No |
| 2023-01-08 | Sunday | No | No |
| 2023-01-16 | Monday | Yes | No |
Best Practices
Creating Your Holiday List
For the calculated field to work, you need a list of holidays. You can create this in several ways:
- Create a separate data source with a column for dates and a column indicating if it's a holiday
- Use a Tableau parameter with a list of dates
- Connect to an external calendar service that provides holiday data
Tip: Consider creating a separate "Holidays" data source that you can join to your main data source when needed.
Testing Your Calculated Field
Always test your calculated field with different date ranges to ensure it works as expected. Check edge cases like:
- Dates at the beginning and end of months
- Dates around holiday periods
- Leap years (February 29)
Performance Considerations
If you're working with large datasets, be mindful of performance. Complex calculated fields can slow down your workbook. Consider:
- Using extract filters instead of calculated fields when possible
- Creating pre-filtered extracts
- Using Tableau's performance recording feature to identify bottlenecks