Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
lk94
Regular 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.

The holidays are in a seperate table. The days, which should be added, are not same for every line and depends on a value, given in the respective line. Also the date, i want to add these days, are given in the respective line.

 

Thank you for your help. Kind

1 ACCEPTED SOLUTION
3 REPLIES 3
Vera_33
Resident Rockstar
Resident Rockstar

Hi @lk94 

 

This is a custom function in M

 

(StartDate as data, EndDate as dateoptional Holiday as tableas 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      
Greg_Deckler
Super User
Super User

@lk94 - Check out Net Work Days - https://community.powerbi.com/t5/Quick-Measures-Gallery/Net-Work-Days/td-p/367362

 

Also, Excel to DAX Translation - https://community.powerbi.com/t5/Community-Blog/Excel-to-DAX-Translation/ba-p/1060991

 

Finally since I see you are a New Member some additional useful links: 

https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.