Skip to content

Commit

Permalink
Fix SubstituteHoliday to match WorkingDays range [2..6] (#49)
Browse files Browse the repository at this point in the history
Fixes an issue where the calculated substitute holiday day is incorrect when `SubstituteHoliday.FridayIfSaturdayOrMondayIfSunday (-1)` is used.
Repro: year `2022` or `2023`, config `{ "US", 12, 25, 0, 0, 0, "Christmas Day", -1, 100, 0, 0 }`

This patch aims for preserving backward compatibility instead of breaking the current configuration value `{ 2, 3, 4, 5, 6 }`, which is used in multiple date templates.

A change to the documentation is also required here: https://docs.sqlbi.com/dax-template/configuration/config-object/holidays#workingdays to update the statement "The weekdays are expressed by integer numbers where Sunday is 0" where Sunday should be 1 instead of 0.
  • Loading branch information
albertospelta authored Apr 11, 2024
1 parent b7e7dfa commit 2064896
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Dax.Template/Tables/Dates/HolidaysTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ public HolidaysTable(IHolidaysConfig config): base(config)
ERROR ( ""Wrong configuration in {config.HolidaysDefinitionTable}"" )
) ) ) ) ) ) )
// )
VAR __HolidayDay = WEEKDAY ( __HolidayDate, 1 ) - 1
VAR __HolidayDay = WEEKDAY ( __HolidayDate, 1 )
VAR __SubstituteHolidayOffset =
// SWITCH (
// TRUE,
IF ( '{config.HolidaysDefinitionTable}'[SubstituteHoliday] = -1,
SWITCH (
__HolidayDay,
0, 1, -- If it falls on a Sunday then it is observed on Monday
6, -1, -- If it falls on a Saturday then it is observed on Friday
1, 1, -- If it falls on a Sunday then it is observed on Monday
7, -1, -- If it falls on a Saturday then it is observed on Friday
0
),
IF ( '{config.HolidaysDefinitionTable}'[SubstituteHoliday] > 0
Expand Down Expand Up @@ -259,7 +259,7 @@ RETURN ROW (
VAR _SubstituteOffsetStep1 = [@SubstituteHolidayOffset] + _ConflictDay0 + _ConflictDay1 + _ConflictDay2
VAR _HolidayDateStep1 = _CurrentHolidayDate + _SubstituteOffsetStep1
VAR _HolidayDayStep1 =
WEEKDAY ( _HolidayDateStep1, 1 ) - 1
WEEKDAY ( _HolidayDateStep1, 1 )
VAR _SubstituteHolidayOffsetNonWorkingDays =
IF (
NOT CONTAINS ( __WorkingDays, ''[Value], _HolidayDayStep1 ),
Expand Down

0 comments on commit 2064896

Please sign in to comment.