Forum Discussion
Date: weekends and holidays
Hello,
I have a starting date and an ending date and I need to count only the working days in between. In other words, the date difference (DATEIFF) between the ending and the starting without taking into consideration the weekends and the holidays.
I tried using WEEKDAY but I couldn't manage to get to the days within the given interval and decrease the difference count at every special date encounter.
How can I achieve this?
Thank you,
Sabine O.
7 Replies
- greggyb
Resident Rockstar
Create a field WorkdayFlag that is 1 when the date in question is a working day (not weekend and not holiday, might be useful to maintain separate WeekendFlag and HolidayFlag fields). Then you can just use
WorkDays = SUM( DimDate[WorkdayFlag] )
- SabineOussi
Skilled Sharer
The thing is I need to check every day within the (start date - end date) interval and remove the weekends and holidays, if any.
How can I do that?- greggyb
Resident Rockstar
You don't need to check those conditions if you have a field as I described. The SUM() measure will automatically respect any filters you apply, so you'll get the count of working days. You can apply a filter with a slicer, a visualization cross-filter, or one of a visual-, page-, or report-level filter.
Your holidays must come from some source table because there are no built in functions that know when your organization has holidays. A weekday check is simple, just check for
// Power Query WeekdayFlag = let Weekday = Date.DayOfWeek( [Date] ) ,WeekdayFlag = if Weekday > 0 and Weekday < 6 then 1 else 0 in WeekdayFlag // DAX WeekdayFlag = ( WEEKDAY( DimDate[Date] ) > 1 && WEEKDAY( DimDate[Date] ) < 7 ) * 1Your WorkdayFlag would be as follows:
// Power Query WorkdayFlag = if [WeekdayFlag] = 1 and [HolidayFlag] = 0 then 1 else 0 // DAX WorkdayFlag = IF( DimDate[WeekdayFlag] = 1 && DimDate[HolidayFlag] = 0 ,1 ,0 )Then your count of working days measure is just:
WorkingDays = SUM( DimDate[WorkdayFlag] )
Measures automatically respect filter context.