how to calculate time difference between two datetime columns in hours excluding weekends and business hours in power bi?

Viewed 321

Hi wondering how to calculate time difference between two datetime columns (ENDDATETIME - STARTDATETIME) in hours (accounting mins and secs also) excluding weekends (Sat and Sun) and non-business hours ( between 5 pm to 8 am) in power bi ? Thanks

ID STARTDATETIME ENDDATETIME
102 2019-11-24 13:46:48.000 2019-12-16 04:51:11.000
105 2019-10-17 12:18:18.000 2019-10-31 04:50:57.000
108 2019-11-30 10:56:37.000 2019-12-04 04:51:19.000
110 2019-10-25 17:31:29.000 2019-11-20 04:51:11.000
112 2019-11-25 16:03:02.000 2019-11-25 17:51:04.000
115 2019-11-04 14:12:09.000 2019-11-07 09:00:02.000
1 Answers

Rather then posting the Power Query code here, I would prefer you download the sample power BI file from Here and check the steps for achieving the desired output.

Some steps might have possibilities to combine, but I keep them separate so that you can visualize the changes in each step easily.

This same can be achieved using DAX but I guess the code will be more complex. Please let me know if you face any issue.

Related