Forum Discussion
lk94
6 years agoRegular Visitor
Building Excel WORKDAY-Function in Power BI
Hi everyone, I need a function in PowerBI, which provides the same features like the WORKDAY-function in excel. So I want to add several days to a date in consideration of weekends and holidays. ...
- 6 years ago
lk94 , refer if these can help
https://community.powerbi.com/t5/Desktop/WORKDAY-formula-in-Power-BI/td-p/202383
https://community.powerbi.com/t5/Desktop/Number-of-working-days/td-p/22842
https://www.youtube.com/watch?v=kRACuS4eKWAOr refer 2nd page of this file
https://www.dropbox.com/s/y47ah38sr157l7t/Order_delivery_date_diff.pbix?dl=0
Anonymous
6 years agoNot applicable
Hi lk94
This is a custom function in M
(StartDate as data, EndDate as date, optional Holiday as table) as number =>
let
ListOfHolidays = if Holiday = null then {} else Table.Column(Holiday, "Date"), // put your own column name
NumListOfHolidays = List.Transform(ListOfHolidays, each Number.From(_)),
ListOfDays = if StartDate > EndDate then {Number.From(EndDate)..Number.From(StartDate)} else {Number.From(StartDate)..Number.From(EndDate)},
ListDiff = List.Difference(ListOfDays,ListOfHolidays),
ListSel = List.Select(
List.Transform(ListDiff, each Date.DayOfWeek(Date.From(_), Day.Saturday)), each _ >1
),
Result = if StartDate = null or EndDate = null then null
else if StartDate > EndDate then (List.Count(ListSel)-1)*(-1)
else List.Count(ListSel) -1
in
Result