Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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])
Solved! Go to Solution.
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
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
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
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
To learn more about Power BI, follow me on Twitter or subscribe 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!
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
71 | |
70 | |
43 | |
31 | |
26 |
User | Count |
---|---|
89 | |
49 | |
44 | |
38 | |
37 |