Forum Discussion
Anonymous
5 years agoNot 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 ...
- Anonymous5 years ago
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) VAR Calendar3 = ADDCOLUMNS(Calendar2,"WeekDay",WEEKDAY([Date],2)) RETURN COUNTX(FILTER(Calendar3,[WeekDay]<6),[Date])
Greg_Deckler
5 years agoCommunity Champion
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.
Anonymous
5 years agoNot 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 =
ADDCOLUMNS(
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]))
VAR Calendar2 = ADDCOLUMNS(Calendar1,"WeekDay",WEEKDAY([Date],2))
RETURN COUNTX(FILTER(Calendar2,[WeekDay]<6),[Date])
Here is what the tables display. Am I doing something wrong?