cancel
Showing results for
Did you mean:
Helper I

## Difference between dates considering only working days

I am having a little challenge counting the right number of days between two dates.

If I use DateDiff function it disregards the fact that there are weekend days in the calendar.

If I use Datesbetween function to count the rows in the Date table filtering out weekend days, it works fine only if start date is less then the end date.

I have a situation where start date can be later than the supposedly end date (bad data, i guess).

Is there a work around to count the number of days between two dates (positive or negative) AND count only weekdays?

1 ACCEPTED SOLUTION
Community Support

Hi， @sz

You need to created  calculated column Is_WorkDay =1 or 0 to indicate if its a workday  or not in your calendar table.

``Is_workday = IF( NOT WEEKDAY('Calendar'[Date],2)   in {6,7},1,0) ``

To avoid the situation where the start date is greater than the end date，you can create a calculated column as below in you fact table (here we set two variables "max1"  and "min1" to get the date in the table)

``````_Workdays =
VAR max1 =
MAX ( 'Table'[StartDate], 'Table'[EndDate] )
VAR min1 =
MIN ( 'Table'[StartDate], 'Table'[EndDate] )
RETURN
CALCULATE (
SUM ( 'Calendar'[Is_workday] ),
ALL ( 'Calendar' ),
DATESBETWEEN ( 'Calendar'[Date], min1, max1 )
)``````

Best Regards,
Community Support Team _ Eason

3 REPLIES 3
Community Support

Hi， @sz

You need to created  calculated column Is_WorkDay =1 or 0 to indicate if its a workday  or not in your calendar table.

``Is_workday = IF( NOT WEEKDAY('Calendar'[Date],2)   in {6,7},1,0) ``

To avoid the situation where the start date is greater than the end date，you can create a calculated column as below in you fact table (here we set two variables "max1"  and "min1" to get the date in the table)

``````_Workdays =
VAR max1 =
MAX ( 'Table'[StartDate], 'Table'[EndDate] )
VAR min1 =
MIN ( 'Table'[StartDate], 'Table'[EndDate] )
RETURN
CALCULATE (
SUM ( 'Calendar'[Is_workday] ),
ALL ( 'Calendar' ),
DATESBETWEEN ( 'Calendar'[Date], min1, max1 )
)``````

Best Regards,
Community Support Team _ Eason

Super User IV

@sz , Check the second page work day diff

https://www.dropbox.com/s/y47ah38sr157l7t/Order_delivery_date_diff.pbix?dl=0

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Super User II

@sz Please take a look at this- https://www.sqlbi.com/articles/counting-working-days-in-dax/

Hope it helps.

Nikhil
Hit the Thumbs-up button if you find this informative!!
Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Announcements

#### Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

#### Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

#### Claim Your Badge & Digital Swag!

Check out how to claim yours today!

#### Are You Ready?

Test your skills now with the Cloud Skills Challenge.

Top Solution Authors
Top Kudoed Authors