我写了一个自定义函数来解决这个问题,除非你也需要考虑假期。它有点通用,它可以添加 2 或 200 或 2000 天。Excel 中的等于=WORKDAY(date;days)
函数。
更新:Bibake Uppal建议应该支持减法。为负数添加减法days
。
这里是:
(startDate, days) =>
let
Sign = if days < 0 then -1 else 1, //add a multiplier to enable negative 'days' to be subtracted rather than added
Step1 = List.Dates(Date.AddDays(startDate, Sign), Sign*days + Number.RoundUp(Sign*days/7*3+4,0), #duration(Sign,0,0,0)), //provision list of added days with 3 more days per each added week, starting from startDate + 1 day; This is a bit over-provisioning, but ensures the list is long enough.
Step2 = List.Select(Step1, (item) => Date.DayOfWeek(item, Day.Monday) < 5), // select only workdays
Step3 = List.FirstN(Step2, Sign*days), //select required number of workdays
Output = if days = 0 then startDate else List.Last(Step3)
in
Output
你可以将它保存为查询,命名它,比如说,,AddWorkdays
然后像这样使用:
YourStepName = Table.AddColumn(yourTable, "CustomColumnName",
each AddWorkdays([ETA], if [REF]="1" then 3 else 2)
//note that [REF]="1" filters a text value, not number!
否则你可以在你的代码中插入这个函数
fnAddWorkdays = (startDate, days) =>
let
Sign = if days < 0 then -1 else 1, //add a multiplier to enable negative 'days' to be subtracted rather than added
Step1 = List.Dates(Date.AddDays(startDate, Sign), Sign*days + Number.RoundUp(Sign*days/7*3+4,0), #duration(Sign,0,0,0)), //provision list of added days with 3 more days per each added week, starting from startDate + 1 day; This is a bit over-provisioning, but ensures the list is long enough.
Step2 = List.Select(Step1, (item) => Date.DayOfWeek(item, Day.Monday) < 5), // select only workdays
Step3 = List.FirstN(Step2, Sign*days), //select required number of workdays
Output = if days = 0 then startDate else List.Last(Step3)
in
Output