Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
PhilipLamour
Regular 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 weekend or a Holiday the "Cut Off" will be the business day prior.  So If the 20th is on a sunday the cut off date will be that Friday th 18th.  However if the 20th is on a sunday but we have a holiday on the that Friday and Thursday the Cut off would be the 16th (Wednesday). 

I created a calendar query with dates from 1/1/21 to 12/31/25, I added a column which shows holidays as well as another column that shows the day of the week.  

Where I am stuck is creating a conditional column that will set the Cutoff date correctly if the 20th of the month falls on the weekend, or a holiday.  

Any ideas?  

1 REPLY 1
Daryl-Lynch-Bzy
Community Champion
Community Champion

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"

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors