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

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

Reply
jimbob2285
Advocate III
Advocate III

DAX Count working days between two dates

Hi

 

I've come across this DAX code to count the working days between two dates, that uses my date table to define if a day is a working day or not

 

Days Overdue =
CALCULATE(
        COUNTROWS ('Date'),
        DATESBETWEEN ('Date'[Date], Fact[Due], Fact[Completed]),
        'Date'[WD] =  "Yes",
        ALL('Fact')
    ) - 1
 
But it seems to be struggling with negative days, i.e. if the Completed date is before the Due date
 
I've modified the formula, as below, to swap the two dates around if the completed date is before the due date:
 
Days Overdue =
IF(Fact[Completed] < Fact[Due],
    (CALCULATE(
        COUNTROWS ('Date'),
        DATESBETWEEN ('Date'[Date], Fact[Completed], Fact[Due]),        
        'Date'[WD] =  "Yes",
        ALL('Fact')
    ) - 1) * -1,
        CALCULATE(
        COUNTROWS ('Date'),
        DATESBETWEEN ('Date'[Date], Fact[Due], Fact[Completed]),
        'Date'[WD] =  "Yes",
        ALL('Fact')
    ) - 1
 
But I just wanted to check this is the correct approach as it seems more of a work around than a solution, and to understand why the first formula struggles to go back in time
 
Thanks
Jim
1 ACCEPTED SOLUTION
lkhall
Helper I
Helper I

can you use the NETWORKDAYS function ?

 

Working Days Test =

var _StartDate= 2023-07-28
var _EndDate = 2023-07-25

return

NETWORKDAYS(_EndDate,_StartDate,1)

View solution in original post

4 REPLIES 4
lkhall
Helper I
Helper I

can you use the NETWORKDAYS function ?

 

Working Days Test =

var _StartDate= 2023-07-28
var _EndDate = 2023-07-25

return

NETWORKDAYS(_EndDate,_StartDate,1)

Hi

 

Hi Ikhall

 

Thanks, Yes, NETWORKDAYS certainly overcomes the problem of negative days, calculating them correctly, but is there a way to reference a holiday table do you know?  It will be a bit long winded to add each holiday for a single year, with bank holidays and Christams shut down, let alone all those holidays for a number of years

 

Cheers

Jim

what are you using for a date dimension table currently ? 

I've built my own date table in SQL

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.