Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
TheEdwardFancy
New Member

Dynamic networkdays function in measure

Hi all!

 

I'm trying to build a measure that allows me to work out the networkdays in a measure.

I have the summary data below:

 

ItemPackageStart DateEnd Date
OrangesOne02/02/202206/08/2022
OrangesTwo15/04/202216/06/2022
ApplesOne01/03/202216/06/2022
BananasOne05/04/202203/10/2022

 

I have a date table so that I can put the months of 2022 in the column headers in a matrix. I want Item in my rows. For my values, I want the total of working days of each month to get:

 

 JanFebMarAprMayJunJul
Apples00232122224
Oranges0192332443421
Pears00019222221

 

I'm circling around an answer using sumx, networkdays, and the min and max of dates, but my table only returns the correct answer when I add 'Package' to the hierarchy and expand it. Can anyone point me in the right direction please?

 Very much appreciated

1 ACCEPTED SOLUTION

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

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

@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.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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

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!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.