I am using the script below to calculate the work day between two days in the power query. But it errors out when there is a negative result. For example, the end date is 3/7 but the start date is 3/9 (End days before the start day).
is there a way to allow this to give me a negative value if we have a negative result? Thank you so much
let
CountBusinessDays = (StartDate as date, EndDate as date) =>
let
numDays = Duration.Days(EndDate - StartDate) + 1,
weekends = List.Select(List.Dates(StartDate, numDays, #duration(1,0,0,0)),
each Date.DayOfWeek(_, Day.Monday) >= 5),
businessDays = numDays - List.Count(weekends)
in
businessDays
in
CountBusinessDays
is there a way to allow this to give me a negative value if we have a negative result? Thank you so much
let
CountBusinessDays = (StartDate as date, EndDate as date) =>
let
numDays = Duration.Days(EndDate - StartDate) + 1,
weekends = List.Select(List.Dates(StartDate, numDays, #duration(1,0,0,0)),
each Date.DayOfWeek(_, Day.Monday) >= 5),
businessDays = numDays - List.Count(weekends)
in
businessDays
in
CountBusinessDays