Tableau Calculated Field Aging Week Days Without Holidays
This guide explains how to create a Tableau calculated field that calculates aging in week days excluding holidays. The formula accounts for weekends and custom holiday dates to provide accurate business days between two dates.
How to Create This Calculated Field
To create a calculated field in Tableau that calculates aging in week days excluding holidays:
- Open your Tableau workbook and connect to your data source.
- Right-click on the Measures or Dimensions pane and select "Create Calculated Field".
- Name your calculated field (e.g., "Aging Week Days Without Holidays").
- Enter the formula shown below in the formula editor.
- Click OK to create the calculated field.
Formula:
DATEDIFF('day', [Start Date], [End Date]) -
SUM(IF WEEKDAY(DATEADD('day', -1, [Start Date]), 'sunday') = 1 OR
WEEKDAY(DATEADD('day', -1, [Start Date]), 'sunday') = 0 OR
[Date] IN [Holiday List] THEN 1 ELSE 0 END)
The formula works by:
- Calculating the total days between the start and end dates
- Subtracting weekends (Saturdays and Sundays)
- Subtracting any custom holiday dates you've defined
Formula Explanation
The formula consists of two main parts:
1. Total Days Calculation
The DATEDIFF function calculates the total number of days between the start and end dates:
DATEDIFF('day', [Start Date], [End Date])
2. Weekend and Holiday Adjustment
The SUM function counts and subtracts weekends and holidays:
SUM(IF WEEKDAY(DATEADD('day', -1, [Start Date]), 'sunday') = 1 OR
WEEKDAY(DATEADD('day', -1, [Start Date]), 'sunday') = 0 OR
[Date] IN [Holiday List] THEN 1 ELSE 0 END)
This part checks each day in the date range and:
- Identifies weekends (Saturdays and Sundays)
- Checks against a predefined list of holidays
- Counts each day that is either a weekend or holiday
Note: You'll need to create a separate data source or parameter for your holiday list in Tableau.
Worked Example
Let's walk through an example to see how this formula works in practice.
Scenario
We have a start date of January 1, 2023 and an end date of January 10, 2023. The holidays in this period are January 2 (New Year's Day) and January 16 (Martin Luther King Jr. Day).
Calculation Steps
- Total days between January 1 and January 10: 9 days
- Weekends in this period: January 7 (Saturday) and January 8 (Sunday)
- Holidays in this period: January 2 (New Year's Day)
- Total non-business days: 3 (January 2, 7, 8)
- Business days: 9 - 3 = 6 days
Using our calculator in the sidebar, you can verify this calculation with your own dates and holiday list.
Frequently Asked Questions
How do I define my holiday list in Tableau?
You can create a separate data source in Tableau containing your holiday dates, or use a parameter to input holidays manually. The formula checks if dates match any in your holiday list.
Can I use this formula with different date ranges?
Yes, the formula is designed to work with any date range. Just replace [Start Date] and [End Date] with your actual date fields.
What if I need to adjust for different weekend definitions?
The formula currently treats Saturday and Sunday as weekends. If your organization has different weekend definitions, you can modify the WEEKDAY function parameters accordingly.
How accurate is this calculation compared to manual counting?
This formula provides the same accuracy as manual counting of business days, minus weekends and holidays. It's a reliable way to automate what would otherwise be a time-consuming manual process.