Reply
Txtcher
Resolver I
Resolver I

Add 10 Business Days to Date Excluding Holidays

I am working in Power Query only and need an M-code function (not a DAX solution).

 

I need to add 10 business days (no Sundays or Saturdays) to an Assigned Date, excluding holidays, to come up with a Due Date. For example, if the Assigned Date is 1/19/2025, the Due Date would be: 2/3/2025.

 

I have a holiday table with a date column: Fed_Holidays.[Date]

 

I have searched for hours to find a solution and can only find solutions to calculate net working days between 2 dates which is not what I need. Unfortunately, I am too inexperienced to convert those solutions into the solution I need, therefore I need your help.

 

Thank you in advance.

2 ACCEPTED SOLUTIONS
ronrsnfld
Super User
Super User

Unless there are some holidays in late January, I don't understand how you get 2/3/2025 by adding 10 business days to 1/19/2025.

 

I see the following:

ronrsnfld_0-1742933326072.png

 

If that analysis is correct, then you can use this Power Query custom function to add Workdays:

(startDt as date, Count as number, Holidays as list)=>

[a=List.Generate(
    ()=>[d=Date.AddDays(startDt,Number.Sign(Count)), 
         idx=if Date.DayOfWeek(d,Day.Monday)>=5 or List.Contains(Holidays,d) then 0 else 1],
    each [idx] <= Number.Abs(Count),
    each [d=Date.AddDays([d],Number.Sign(Count)), 
         idx=if Date.DayOfWeek(d,Day.Monday)>=5 or List.Contains(Holidays,d) then [idx] else [idx] + 1],
    each [d]),
 b=List.Select(a, each Date.DayOfWeek(_,Day.Monday)<5 and not List.Contains(Holidays,_)),
 c=List.Last(b)][c]

 

 

View solution in original post

The input arguments are obvious by their names.

 

You will need to familiarize yourself with the various functions used in the custom function.

 

We use the Date.Add function embedded in the List.Generate function to create a list of dates.

But we only increment the Counter (idx) if the generated date is not a holiday or weekend.

 

Because the Counter is not being incremented on non-business days, there is a chance that the final dates might occur on a non-business day, so we need to remove non-business days from the final list.

 

We then return the last date in the list.

View solution in original post

7 REPLIES 7
ronrsnfld
Super User
Super User

Unless there are some holidays in late January, I don't understand how you get 2/3/2025 by adding 10 business days to 1/19/2025.

 

I see the following:

ronrsnfld_0-1742933326072.png

 

If that analysis is correct, then you can use this Power Query custom function to add Workdays:

(startDt as date, Count as number, Holidays as list)=>

[a=List.Generate(
    ()=>[d=Date.AddDays(startDt,Number.Sign(Count)), 
         idx=if Date.DayOfWeek(d,Day.Monday)>=5 or List.Contains(Holidays,d) then 0 else 1],
    each [idx] <= Number.Abs(Count),
    each [d=Date.AddDays([d],Number.Sign(Count)), 
         idx=if Date.DayOfWeek(d,Day.Monday)>=5 or List.Contains(Holidays,d) then [idx] else [idx] + 1],
    each [d]),
 b=List.Select(a, each Date.DayOfWeek(_,Day.Monday)<5 and not List.Contains(Holidays,_)),
 c=List.Last(b)][c]

 

 

Hello,

January 20 is a federal holiday in the US, so that makes the date February 3, because the 1st and the 2nd are Sat & Sun.

In that case, the function will work as is. Did you try it?

Yes, thank you. I did try it. And it works perfectly. However, I am not comfortable using something I don't understand. I know it is a big ask, but can you step me through it?

 

Again, thank you.

The input arguments are obvious by their names.

 

You will need to familiarize yourself with the various functions used in the custom function.

 

We use the Date.Add function embedded in the List.Generate function to create a list of dates.

But we only increment the Counter (idx) if the generated date is not a holiday or weekend.

 

Because the Counter is not being incremented on non-business days, there is a chance that the final dates might occur on a non-business day, so we need to remove non-business days from the final list.

 

We then return the last date in the list.

Okay now the lights are flickering. I understood some of the functions, but missed the date functions were in the context of List.Generate (newbie using List functions).

 

This part confuses me: Number.Sign(Count)*1

The function returns a 1 for a positive number or -1 for a negative number: Number.Sign(10) returns 1. But why multiply it by 1?

 

Thank you for your time and generosity. 

Nice catch. The *1 is unnecessary. I Put it in during troubleshooting and forgot to remove it.

avatar user

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)