Forum Discussion
PhilipLamour
3 years agoRegular Visitor
Creating a Cut off date
I am attempting to create a query that uses calendar dates to highlight when a "cutoff" is supposed to happen each month. The Cutt off date is the 20th of each month, however is the 20th falls on a ...
Anonymous
3 years agoNot applicable
Hi PhilipLamour - The following code can be adapted if you can provide a list of the Holidays.
let
#"List of Holidays" = { #date(2021,1,1) , #date(2022,1,1), #date(2023,1,1) } ,
Source = List.Dates( #date(2021,12,31), 365 * 5 + 1, #duration(1,0,0,0) ),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), type table[Date = Date.Type]),
#"Add Weekends" = Table.AddColumn(#"Converted to Table", "IsWeekend", each Date.DayOfWeek([Date]) = Day.Saturday or Date.DayOfWeek( [Date]) = Day.Sunday, type logical),
#"Added Custom" = Table.AddColumn(#"Add Weekends", "IsHoliday", each List.Contains( #"List of Holidays" , [Date] ), type logical),
#"Inserted Start of Month" = Table.AddColumn(#"Added Custom", "Start of Month", each Date.StartOfMonth([Date]), type date),
#"List of Cut Off Dates" =
Table.Group(
#"Inserted Start of Month",
{"Start of Month"},
{
{
"CutOffDate",
(x) =>
List.Max(
Table.SelectRows(
x ,
each Date.Day([Date]) <= 20 and not [IsWeekend] and not [IsHoliday]
)[Date]
),
type date
}
}
)[CutOffDate],
#"Add Cut Off Flag" = Table.AddColumn(#"Inserted Start of Month", "IsCutOffDate", each List.Contains( #"List of Cut Off Dates" , [Date] ) , type logical)
in
#"Add Cut Off Flag"