I have a date table with a date column. I would like to have a weekly period for each month. So far, I have built a custom column such that each period starts on Monday and ends on Sunday:
let
startOfWeek = Date.StartOfWeek([Date]),
endOfWeek = Date.EndOfWeek([Date]),
yearOfStartOfWeek = Date.Year(startOfWeek),
yearOfEndOfWeek = Date.Year(endOfWeek),
valueToReturn = if yearOfStartOfWeek = yearOfEndOfWeek then
Text.From(Date.StartOfWeek([Date])) & " - " & Text.From(Date.EndOfWeek([Date]))
else
Text.From(Date.StartOfWeek([Date])) & " - " & Text.From(Date.EndOfWeek(endOfWeek))
in valueToReturn
This will give me the custom column "Weekly Period" below:
But what I need to have is this way of weekly period:
The first week for each month starts with first day of the month and that has to be a working day (not weekend). For example the first week of Sep 2019 starts with Monday 2nd . Also, the last weekly period for each month ends with the last day of month.
Do you know how to change this code or which other codes I need to use to have This weekly period like the column below? Many Thanks.
Also I want another column that gives me the week numbers of the months, as above. I would be grateful if someone can help me build this two custom columns in the date table.
For those that might be helpful, here I found the answer for Weekly Period:
let
startOfWeek = Date.StartOfWeek([Date]),
endOfWeek = Date.EndOfWeek([Date]),
weekOfStartOfWeek = Date.WeekOfYear(startOfWeek),
weekOfEndOfWeek = Date.WeekOfYear(endOfWeek),
valueToReturn = if (Date.Month(Date.StartOfWeek([Date])) = Date.Month([Date]) and Date.Month(Date.EndOfWeek([Date])) = Date.Month([Date]))
then
Text.From(Date.StartOfWeek([Date])) & " - " & Text.From(Date.EndOfWeek([Date]))
else if Date.Month(Date.StartOfWeek([Date])) <> Date.Month([Date]) then
Text.From([Date.StartOfMonth([Date])]) & " - " & Text.From(Date.EndOfWeek(endOfWeek))
else
Text.From(Date.StartOfWeek([Date])) & " - " & Text.From(Date.EndOfMonth([Date]))
in
valueToReturn