Forum Discussion
jcamilo1985
Helper III
3 years agocalculate date without holidays (only working days)
Good night After trying for several hours I had no choice but to resort to your help I have the following challenge, I have a table with a date to which I have to add a number of days based on a co...
jcamilo1985
Helper III
3 years agoThank you very much for your commitment and interest in this topic AlienSx .
After several attempts, I was finally able to find the solution, but all thanks to the base that you gave me.
Here I share it in case someone else needs it at some point.
In the same way thanks to the other people who read the thread and were interested.
(start as date, days as number, holidays as list) as date =>
let
dates = List.Generate(
() => [
date = start,
count = 1,
holiday = List.Contains(holidays, start)
or List.Contains({5, 6}, Date.DayOfWeek(start, Day.Monday))
],
each [count] <= days,
each [
date = Date.AddDays([date], 1),
count = [count] + (if [holiday] then 0 else 1),
holiday = List.Contains(holidays, Date.AddDays([date], 1))
or List.Contains({5, 6}, Date.DayOfWeek(Date.AddDays([date], 1), Day.Monday))
],
each [date]
),
result = List.LastN(dates, 1){0}
in
result
AgataJ
Helper II
1 year agoHi jcamilo1985 , thanks for sharing the working solution, this is exactly what I needed today!