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.
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!
Solved! Go to Solution.
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])
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])
@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.
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?
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
49 | |
25 | |
20 | |
15 | |
12 |
User | Count |
---|---|
57 | |
49 | |
44 | |
18 | |
18 |