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

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.

Reply
pears980
New Member

Number of days between date columns excluding weekends

# of Days = DATEDIFF('EAM-XXPXD-XXPXD_EAM_ZOHO_WORKREQUEST'[CREATION_DATE],'EAM-XXPXD-XXPXD_EAM_ZOHO_WORKREQUEST'[LAST_UPDATE_DATE],DAY)

pears980_0-1636408444113.png

This if formula i have cant seem to figure out how to tell it to not count weekends.

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @pears980 ,

 

To calculate the number of days excluding weekends, you can create a calendar table first. No relationship between the calendar and the main table.

Calendar = CALENDAR(DATE(2021,1,1),DATE(2021,12,31))

Then create a measure

# of Days = CALCULATE(COUNT('Calendar'[Date]),FILTER('Calendar',[Date]>=MAX('Table'[StartDate])&&[Date]<=MAX('Table'[EndDate])&&[Weekday]<>6&&[Weekday]<>7))

15.png

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

2 REPLIES 2
v-stephen-msft
Community Support
Community Support

Hi @pears980 ,

 

To calculate the number of days excluding weekends, you can create a calendar table first. No relationship between the calendar and the main table.

Calendar = CALENDAR(DATE(2021,1,1),DATE(2021,12,31))

Then create a measure

# of Days = CALCULATE(COUNT('Calendar'[Date]),FILTER('Calendar',[Date]>=MAX('Table'[StartDate])&&[Date]<=MAX('Table'[EndDate])&&[Weekday]<>6&&[Weekday]<>7))

15.png

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

PhilipTreacy
Super User
Super User

Hi @pears980 

 

You need to set up a date table which can be used to see what dates are Sat or Sun.  You can then write something like this

 

# of Days = DATEDIFF('EAM-XXPXD-XXPXD_EAM_ZOHO_WORKREQUEST'[CREATION_DATE],'EAM-XXPXD-XXPXD_EAM_ZOHO_WORKREQUEST'[LAST_UPDATE_DATE],DAY) - ABS(CALCULATE(COUNTROWS('DateTable'[Date]), FILTER('DateTable', 'DateTable'[Date] <= 'EAM-XXPXD-XXPXD_EAM_ZOHO_WORKREQUEST'[CREATION_DATE] && 'DateTable'[Date] >= 'EAM-XXPXD-XXPXD_EAM_ZOHO_WORKREQUEST'[LAST_UPDATE_DATE] && DAY('DateTable'[Date]) <> 1 && DAY('DateTable'[Date]) <> 7)))

 

NOTE: My PC is playing up and Power BI won't start so I haven't tested that code yet.  Will reboot then test and edit as required.

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.