Forum Discussion
Dynamic networkdays function in measure
- 3 years ago
I used a workaround by using countrows on my data table and filtering out weekends. SUMX then calculated it by item and totalled the answer
TheEdwardFancy You'll have to get the MIN start date and MAX end date and then calculate the number of working days, something like:
Measure =
VAR __Min = MIN('Table'[Start Date])
VAR __Max = MAX('Table'[End Date])
VAR __Result = NETWORKDAYS(__Min, __Max)
RETURN
__Result
You may also need to combine this with something like Time Intervals:
Take a look at these two Quick Measures as I think you want something like them.
https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364
https://community.powerbi.com/t5/Quick-Measures-Gallery/Periodic-Billing/m-p/409365
Not sure what your current calculation looks like.
Thanks for this Greg_Deckler. This is my current measure at the moment:
VAR StartMonth = EOMONTH(max('DateTable'[Month]),-1)+1
VAR EndMonth = max('DateTable'[Month])
RETURN calculate(
sumx('Data',
if(
or (max('Data'[Start Date])>= EndMonth,
max('Data'[End Date])<=StartMonth),0,
NETWORKDAYS(
max(StartMonth,max('Data'[Start Date])),
min(EndMonth,max('Data'[End Date]))
)
)
)
)
Which gives me the results in my OP. My problem is that my dates span across months, so I can't just have a standard networkday calculation with the start and end dates from the columns. Apologies if I'm not explaining myself properly, but I appreciate your reply!