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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
jslayer111
Frequent Visitor

calculate working days

I am using the below function to determine working days but I need it to show 0 if the start date and complted date is the same.  How can I do this?

 

= "(InitialDate as date, FinalDate as date ) as number => #(lf)let#(lf)DaysBetweenDates = Duration.Days(FinalDate-InitialDate),#(lf)DaysList = List.Dates(List.Min({InitialDate,FinalDate}),Number.Abs(DaysBetweenDates)+1, Duration.From(1)),#(lf)WeekDaysList = List.Select(DaysList, each (Date.DayOfWeek(_, Day.Monday) < 5) ),#(lf)WorkingDays = (if DaysBetweenDates < 0 then -1 else 1) * List.Count(WeekDaysList)#(lf)in#(lf)WorkingDays"

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @jslayer111 

Change the query so that the last couple of lines are

#WorkingDays = (if DaysBetweenDates < 0 then -1 else 1) * List.Count(WeekDaysList),
Result = if InitialDate - FinalDate = 0 then 0 else #WorkingDays
        
in
    Result

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

1 REPLY 1
PhilipTreacy
Super User
Super User

Hi @jslayer111 

Change the query so that the last couple of lines are

#WorkingDays = (if DaysBetweenDates < 0 then -1 else 1) * List.Count(WeekDaysList),
Result = if InitialDate - FinalDate = 0 then 0 else #WorkingDays
        
in
    Result

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors