08-06-2022 10:41 AM - last edited 08-07-2022 19:59 PM
Power BI in July 2022 has released a new DAX function Networkdays.
I would like to explore the same here. I have uploaded the file used in this blog on GitHub. There are two tables. One with two dates to get networkdays and the second having US holidays for the Year 2022.
Networkdays function can take 4 parameters and the last two are optional
1. Start Date
2. End Date
3. Week End
4. Holidays
Power BI has given various weekend options, which you can find in the document. The common one is 1 which means the weekend is Saturday and Sunday
The traditional method to get the workdays between two dates was
Work Days Traditional 1 = Countrows(filter( CALENDAR([Date1],Dates[Date2]), WEEKDAY([Date],2) <6 ))
The same can be achieved using
Work Days 1 = NETWORKDAYS(Dates[Date1],Dates[Date2],1)
You can add holidays using the table, for example, manual table addition
Work Days 2 = NETWORKDAYS(Dates[Date1],Dates[Date2],1, {Date(2022,1,17)})
In the old method, you need to do
Work Days Traditional 2 = Countrows(filter( CALENDAR([Date1],Dates[Date2]), WEEKDAY([Date],2) <6 && not [Date] in {Date(2022,01,17)}))
You can use a calendar table, I will use the one I loaded into the file. I have more than one column. I am taking only one. I can use distinct to all.
Work Days = NETWORKDAYS(Dates[Date1],Dates[Date2],1, distinct(Holidays[Date]))
In the old method, you need to do
Work Days Traditional = Countrows(filter( CALENDAR([Date1],Dates[Date2]), WEEKDAY([Date],2) <6 && not [Date] in distinct(Holidays[Date])))
Please let find the blog here. Like, Share, and Comment.