To convert any of these columns to measures, we simply need to replace the first line with the following:
VAR __Date = MAX([Date])
For all of these calculations except First Working Day of Week, if we want to know the last working day of the period in question, we simply need to edit the line above the RETURN line to use MAXX instead of MINX.
To find the last working day of a week, we use this formula:
Last Working Day of Week =
VAR __Date = 'R07_Calendar'[Date]
VAR __Calendar =
FILTER(
ADDCOLUMNS(
CALENDAR(__Date - 5 ,__Date + 5),
"__WeekNum",WEEKNUM('R07_Calendar'[Date]),
"__WeekDay",WEEKDAY('R07_Calendar'[Date], 2)
),
[__WeekDay] = 5
)
VAR __WorkingDay = MAXX(__Calendar,'R07_Calendar'[Date])
RETURN __WorkingDay
Here, we have changed the weekday number that we are filtering on from a 1 (Monday) to a 5 (Friday) and are using a MAXX function instead of a MINX function in our calculation for the __WorkingDay variable.
There is a variation for finding the first and last working days of weeks. The formulas presented span years, such that, if a week starts or ends in a previous or subsequent year, the formula returns the date in that previous or subsequent year. If it is instead desired to only include the start and end working days for a week within the same year, use this variation for First Working Day of Week:
First Working Day of Week 2 =
VAR __Date = 'R07_Calendar'[Date]
VAR __WeekNum = WEEKNUM(__Date)
VAR __Calendar =
FILTER(
ADDCOLUMNS(
CALENDAR(__Date - 5 ,__Date + 5),
"__WeekNum",WEEKNUM('R07_Calendar'[Date]),
"__WeekDay",WEEKDAY('R07_Calendar'[Date], 2)
),
[__WeekNum] = __WeekNum &&
[__WeekDay] < 6
)
VAR __WorkingDay = MINX(__Calendar,'R07_Calendar'[Date])
RETURN __WorkingDay
For the same variation for Last Working Day of Week, simply replace the MINX function in this variation with the MAXX function in the line immediately above the RETURN line.
Finally, if you are using non-standard calendar quarters, simply edit the calculation for the __Quarter variable and the __Quarter column to correspond with your custom quarter calculation. Refer to the Creating quarters recipe in this chapter.