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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Dunner2020
Post Prodigy
Post Prodigy

Difference of dates in days by excluding weekends (power query)

Hi there,

 

I want to calculate the difference of two dates in days by excluding weekends in power query. I got a date table which has columns that tells whether the date lies on weekday and weekend.  I used the following formula for calculating the difference in days but dont know how to exclude the weekends. Any help would be really appreciated.

 

Duration.Days([Date1] - [Date2])

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Here is one way to do it with a custom column with this formula (Date2 is the earlier date in this case).

 

= List.Count(List.Select(List.Dates([Date2], Duration.TotalDays([Date1]-[Date2]) + 1, #duration(1,0,0,0)), each List.Contains({1,2,3,4,5}, Date.DayOfWeek(_))))

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi @Dunner2020,

Did mahoneypat 's suggestions help with your scenario? if that is the case, you can consider Kudo or accept his suggestions to help others who faced similar requirements.

If the above doesn't help, please share more detailed information to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

mahoneypat
Microsoft Employee
Microsoft Employee

Here is one way to do it with a custom column with this formula (Date2 is the earlier date in this case).

 

= List.Count(List.Select(List.Dates([Date2], Duration.TotalDays([Date1]-[Date2]) + 1, #duration(1,0,0,0)), each List.Contains({1,2,3,4,5}, Date.DayOfWeek(_))))

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


This is incredible, thank you.

 

I made a revision that hopefully improves performance.  Date.DayOfWeek([Date],1) will offset the value by 1, so you just need to test < 5 instead of compare a list.

 

Date2 being the earlier date:

 

= List.Count(List.Select(List.Dates([Date2], Duration.TotalDays([Date1]-[Date2]) + 1, #duration(1,0,0,0)), each Date.DayOfWeek(_,1) < 5))

 

 

Thank you for this - solved a big problem in calculating SLA numbers.

I agree, and used @mahoneypat's reply for the very same purpose in December 2021. 

How beatiful is this code

I believe that the List.Contains({1,2,3,4,5} should actually be List.Contains({0,1,2,3,4}, otherwise this works perfectly! Thank you!

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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