cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kparab Frequent Visitor
Frequent Visitor

How to calculate difference between two date/time in seconds excluding weekends and holidays .

Hi All,

 

I need to calculate difference between this Created_date and Credit_hold_date columns in seconds by excluding weekends and holidays. 

Any help would be appreciated . 

 

sample data : 

table 1 

Created_dateCredit_hold_date
5/07/19 09:52:27 AM5/07/19 12:09:07 PM
5/21/19 08:24:52 AM5/21/19 02:14:12 PM
6/11/19 02:03:33 PM6/11/19 04:36:44 PM
5/23/19 04:39:14 PM5/29/19 01:58:15 PM
5/29/19 11:43:57 AM5/30/19 02:19:15 PM
5/30/19 03:15:07 PM6/03/19 05:05:27 PM
7/04/19 03:10:49 PM7/05/19 09:44:30 AM
6/28/19 04:01:49 PM7/02/19 09:04:33 AM

 

 

Table 2

DateHolidays
01/01/2019New Year's Day
02/18/2019Family Day
04/19/2019Good Friday
05/20/2019Victoria Day
07/01/2019Canada Day(observed)
08/05/2019Civic Holiday
09/02/2019Labour Day
10/14/2019Thanksgiving Day
12/25/2019Christmas Day
12/26/2019Boxing Day

 

Regards,

Khushboo

1 ACCEPTED SOLUTION

Accepted Solutions
kparab Frequent Visitor
Frequent Visitor

Re: How to calculate difference between two date/time in seconds excluding weekends and holidays .

It worked by changing some code.

 
App_hold_holidays =
COUNTROWS (
FILTER (
'Federal Holiday',
AND (
'Federal Holiday'[Date] >= MApproved_hold_ReleasedManually[Approved_date_time],
'Federal Holiday'[Date] <= MApproved_hold_ReleasedManually[Credit_hold_date_time]
)
)
)
 
Thanks.

View solution in original post

9 REPLIES 9
tex628 New Contributor
New Contributor

Re: How to calculate difference between two date/time in seconds excluding weekends and holidays .

Can the created/hold date occur on a holiday/weekend?

kparab Frequent Visitor
Frequent Visitor

Re: How to calculate difference between two date/time in seconds excluding weekends and holidays .

No .

 

While calculating difference between created/hold date it should exclude weekends and holidays.

tex628 New Contributor
New Contributor

Re: How to calculate difference between two date/time in seconds excluding weekends and holidays .

That makes things alot more simple. 

You should start by creating a column counting the number of red days / weekends between the dates on each row. 

HolidayCount = 
VAR holdDate = 'Table1'[Credit hold date]
VAR createDate = 'Table1'[Created_date]
Return

Calculate(
Countrows('Table2'),
all('Table2'),
'Table2'[Date]<= holdDate ,
'Table2'[Date]>= createDate
)

 

 

 

kparab Frequent Visitor
Frequent Visitor

Re: How to calculate difference between two date/time in seconds excluding weekends and holidays .

Thanks , But My scope is to get the difference between those two columns in seconds by excluding holiday and weekend,

tex628 New Contributor
New Contributor

Re: How to calculate difference between two date/time in seconds excluding weekends and holidays .

It was only the first step. We need that number to be able to know how many seconds to subtract in the next step. 
Are you getting the correct number of red days for each row?

kparab Frequent Visitor
Frequent Visitor

Re: How to calculate difference between two date/time in seconds excluding weekends and holidays .

Yes , How can i exclude weekends?

tex628 New Contributor
New Contributor

Re: How to calculate difference between two date/time in seconds excluding weekends and holidays .

Difference in seconds;

Difference = (Table[Credit_Hold_Date] - Table[Created_Date]) * 24 * 60

Then subtract the seconds from the red days

Difference = ((Table[Credit_Hold_Date] - Table[Created_Date]) * 24 * 60) - (86400 * Table[HolidayCount])


Should give you the correct amount of seconds between the 2 dates, red days excluded.

kparab Frequent Visitor
Frequent Visitor

Re: How to calculate difference between two date/time in seconds excluding weekends and holidays .

I am not getting holiday count even if difference of dates has holidays i.e. July 1 2019OUTLOOK_2019-08-22_18-37-05.pngHoliday Table

Screenshot.pngDax functionvmware-view_2019-08-22_19-01-46.pngValues highlighted

kparab Frequent Visitor
Frequent Visitor

Re: How to calculate difference between two date/time in seconds excluding weekends and holidays .

It worked by changing some code.

 
App_hold_holidays =
COUNTROWS (
FILTER (
'Federal Holiday',
AND (
'Federal Holiday'[Date] >= MApproved_hold_ReleasedManually[Approved_date_time],
'Federal Holiday'[Date] <= MApproved_hold_ReleasedManually[Credit_hold_date_time]
)
)
)
 
Thanks.

View solution in original post

Helpful resources

Announcements
Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 204 members 2,222 guests
Please welcome our newest community members: