Forum Discussion
Calculate due date based on SLA excluding weekends and holidays date conversion error
- 1 year ago
Hi amby0430
There are two clear issues with your code (assuming adbe_holiday_calendar is a list with date type values).
1. The second argument of List.Dates is expects a count as number and you've provided a date: Date.From(Date.AddDays(StartDate,90)) so I guess 90 will do
2. But Result will throw an error as well, RemoveHolidays returns a list of values and can't be converted to a date, however you can for example extract the last date value from that list.
I hope this is helpful
(StartDate as date) as date => let DateList = List.Dates(StartDate, 90, Duration.From(1)), RemoveWeekends = List.Select(DateList, each Date.DayOfWeek(_, Day.Monday) < 5), RemoveHolidays = List.RemoveItems(RemoveWeekends, adbe_holiday_calendar), Result = List.Last(RemoveHolidays) in Result
Hi amby0430,
Thanks m_dekorte for Addressing the issue.
Glad that your issue is resolved! 😊 Could you please accept it as a solution? This will help other community members with similar issues find the solution faster.
Regards,
Vinay Pabbu
m_dekorte I have found that the weekends and holidays are not being removed from the calculation. If you could please kindly respond if you have thoughts or a solution I would appreciate it. Thank you.
- m_dekorte1 year ago
Resident Rockstar
Hi amby0430,
The most obvious reason would be if values in your adbe_holiday_calendar have a different data type. To illustrate, what would you expect to be the outcome here?
let dateTimes = List.DateTimes( DateTime.From(#date(2025, 3, 1)), 10, Duration.From(1)), Dates = List.Dates( #date(2025, 3, 2), 9, Duration.From(1)), Diff = List.RemoveItems( dateTimes, Dates) in DiffHope that helps!