cancel
Showing results for
Did you mean:
Anonymous
Not applicable

## Excel NETWORKDAYS function in PowerBI

Hi all,

I'm trying to pro-rate weekly costs by multiplying the monthly cost by the number of business days that have occured the previos week. For example, I would pull data today (11/10/20) and publish a weekly report that covers data up to the Friday (11/6/2020) of the previous week. For reporting week 11/6/20, there will have been 5 business days in November that have passed; 10 business days on reporting week 11/13, etc; total of 21 business days in the month of November. So the first week will have Monthly Cost * (5/21), the second week (10/21) and so on.

1. How do I get PBI to count the total number of business days per month (21 for November), (23 in December), etc?

2. How do I get PBI to count how many business days have passed in the month since the last report date each week?

FYI I've looked through a few related posts on duplicating the "NETWORK" function from Excel, but I'm receiving errors in my dataset that I can't have dates in the future (ie: 12/1/2020) in my dataset.

Here is what a portion of my dataset looks like. There are 50 other "Projects" with 12 "Monthly Forecast Costs".

Any help would be appreciated! Thank you!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

For those wondering what I ended up doing.

I used Greg's formula below, but I removed all future months from my data set. So I'll have to manually unfilter each month as we get to it. That seems to be the only way to bypass the error of "can't have future days in my dataset."

``````NetWorkDaysCurrentWeek =
VAR Calendar1 = CALENDAR(MAX('Forecast - Grid Enhancement'[Date]),MAX('Forecast - Grid Enhancement'[Reporting Week]))
//VAR Holidays = DATATABLE("Date",DATETIME,{{}})
VAR Holidays1 = DATATABLE("Date",DATETIME,
{
{"11/26/2020 12:00:00 AM"},
{"11/27/2020 12:00:00 AM"},
{"12/24/2020 12:00:00 AM"},
{"12/25/2020 12:00:00 AM"}
})
VAR Calendar2 = EXCEPT(Calendar1,Holidays1)
RETURN COUNTX(FILTER(Calendar3,[WeekDay]<6),[Date])``````
3 REPLIES 3
Anonymous
Not applicable

For those wondering what I ended up doing.

I used Greg's formula below, but I removed all future months from my data set. So I'll have to manually unfilter each month as we get to it. That seems to be the only way to bypass the error of "can't have future days in my dataset."

``````NetWorkDaysCurrentWeek =
VAR Calendar1 = CALENDAR(MAX('Forecast - Grid Enhancement'[Date]),MAX('Forecast - Grid Enhancement'[Reporting Week]))
//VAR Holidays = DATATABLE("Date",DATETIME,{{}})
VAR Holidays1 = DATATABLE("Date",DATETIME,
{
{"11/26/2020 12:00:00 AM"},
{"11/27/2020 12:00:00 AM"},
{"12/24/2020 12:00:00 AM"},
{"12/25/2020 12:00:00 AM"}
})
VAR Calendar2 = EXCEPT(Calendar1,Holidays1)
RETURN COUNTX(FILTER(Calendar3,[WeekDay]<6),[Date])``````
Super User

@Anonymous Have you read through this? https://community.powerbi.com/t5/Quick-Measures-Gallery/Net-Work-Days/m-p/367362#M109. Also, Chapter 2, Recipe 10 of my book DAX Cookbook has an improved version of this. https://github.com/gdeckler/DAXCookbook. You can download the PBIX from there.

Check out my External Tool for Power BI Desktop! Microsoft Hates Greg's Quick Measures
Check out my latest book!

Anonymous
Not applicable

Hey @Greg_Deckler ,

Thanks for your feedback. I created 2 measures based on your examples...

``````NetWorkDays1 =
VAR __Date1 = MAX('Forecast - Grid Enhancement'[Todays Date])
VAR __Date2 = MAX('Baseline Forecast'[Date])
VAR __Date1a = MINX( { __Date1, __Date2 },[Value])
VAR __Date2a = MAXX( { __Date1, __Date2 },[Value])
VAR __Calendar =
CALENDAR(__Date1a, __Date2a),
"__WeekDay",
WEEKDAY([Date],2)
)
RETURN
COUNTX(
FILTER(
__Calendar,
[__WeekDay] < 6
),
[Date]
)``````
``````NetworkDays2 =
VAR Calendar1 = CALENDAR(MAX('Baseline Forecast'[Date]),MAX('Forecast - Grid Enhancement'[Reporting Week]))
RETURN COUNTX(FILTER(Calendar2,[WeekDay]<6),[Date])``````

Here is what the tables display. Am I doing something wrong?

Announcements

#### Launching new user group features

Learn how to create your own user groups today!