Greg_Deckler
8 years agoCommunity Champion
First/Last Working Days
Builds off of First Working Day of Week here: https://community.powerbi.com/t5/Quick-Measures-Gallery/First-Working-Day-of-Week/m-p/391332
Provides the same functionality for First/Last Working...
Anonymous
4 years agoNot applicable
Appreciate this is an old topic but this bit of code has really helped, thank you!
I have modified the last working day to find the last saturday for a maintenance weekend, this works really nice thanks to your code
Maintenance Check =
//this calculates the approximate date of the monthly maintenance window it looks at the weekday as 6 = Saturday then takes the max valule of the calculated calendar and subtracts 7 If the last Saturday is after the last working day, otherwise it displays the last working Saturday of the month
VAR TodaysDate = today()
VAR Calendar1 = CALENDAR(DATE(YEAR(TodaysDate),1,1),DATE(YEAR(TodaysDate),12,31))
VAR Calendar2 = ADDCOLUMNS(Calendar1,"Month",MONTH([Date]))
VAR Calendar3 = ADDCOLUMNS(Calendar2,"WeekDay",WEEKDAY([Date],2))
VAR TodaysMonth = MONTH(TodaysDate)
VAR Calendar4 = FILTER(Calendar3,[Month]=TodaysMonth&&[WeekDay]<6)//calculate the last working day of the month
VAR Calendar5 = FILTER(Calendar3,[Month]=TodaysMonth&&[WeekDay]=6)//calculate the last Saturday of the month
VAR LastWorkingDay = MAXX(Calendar4,[Date])
VAR LastSaturday = MAXX(Calendar5,[Date])
RETURN if(LastWorkingDay<LastSaturday,format(LastSaturday-7,"dd/mmm/yyyy"),//this takes into account months where the last saturday is the last or next to last day, minus 7 and thats the MM weekend
FORMAT(LastSaturday,"dd/mmm/yyyy"))