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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
flaviobdsti
Helper I
Helper I

Seeking Assistance with Date/Time Calculations and Excluding Holidays and Non-Productive Hours

Hello, everyone. I've been struggling for a few days to solve an issue involving date/time calculations. If anyone can help me, I'll be grateful.

I have a table called dimTime, which was generated from another table. I have two columns in the date/time format called Start and End. I need to know how many minutes are between the two dates, taking into account the employee's working hours, which are from 08:00:00 to 17:00:00, and excluding Saturdays and Sundays.

Can you help me? I've searched, conducted several simulations, looked in the ChatGPT, and still couldn't find a solution.
I appreciate it in advance.

dimTime

flaviobdsti_0-1703857377084.png


dimHoliday

flaviobdsti_1-1703857550545.png


Productive work interval: 08:00:00 to 17:00:00



1 ACCEPTED SOLUTION
Dangar332
Super User
Super User

Hi, @flaviobdsti 

in earlier post it some mistake 

as i understood below is your solution

total minute = 
var a = 
     var a1 = FORMAT(TIME(17,00,00)-FORMAT('Table (5)'[start],"hh:MM:ss"),"hh:MM:ss")
     var a2 = HOUR(a1)*60 +MINUTE(a1) +(SECOND(a1)/100)
     return a2
var b =
     var b1 = FORMAT(FORMAT('Table (5)'[end]-TIME(8,00,00),"hh:MM:ss"),"hh:MM:ss")
     var b2= HOUR(b1)*60 +MINUTE(b1) +(SECOND(b1)/100)
     RETURN b2
var c = a+b
var d= 
       var d1 =FORMAT('Table (5)'[end]-'Table (5)'[start],"hh:mm:ss")
       var d2 = HOUR(d1)*60+MINUTE(d1)+(SECOND(d1)/100)
       RETURN d2
var e = NETWORKDAYS('Table (5)'[start],'Table (5)'[end],1,ALL('Table (5)'[holiday]))
var f =c+ ((e-1)*9*60)
RETURN
SWITCH(TRUE(),
        e=1,d,
        e=2,c,
        e>2,f)

 

Dangar332_0-1703874369190.png

 

View solution in original post

5 REPLIES 5
Dangar332
Super User
Super User

Hi, @flaviobdsti 

in earlier post it some mistake 

as i understood below is your solution

total minute = 
var a = 
     var a1 = FORMAT(TIME(17,00,00)-FORMAT('Table (5)'[start],"hh:MM:ss"),"hh:MM:ss")
     var a2 = HOUR(a1)*60 +MINUTE(a1) +(SECOND(a1)/100)
     return a2
var b =
     var b1 = FORMAT(FORMAT('Table (5)'[end]-TIME(8,00,00),"hh:MM:ss"),"hh:MM:ss")
     var b2= HOUR(b1)*60 +MINUTE(b1) +(SECOND(b1)/100)
     RETURN b2
var c = a+b
var d= 
       var d1 =FORMAT('Table (5)'[end]-'Table (5)'[start],"hh:mm:ss")
       var d2 = HOUR(d1)*60+MINUTE(d1)+(SECOND(d1)/100)
       RETURN d2
var e = NETWORKDAYS('Table (5)'[start],'Table (5)'[end],1,ALL('Table (5)'[holiday]))
var f =c+ ((e-1)*9*60)
RETURN
SWITCH(TRUE(),
        e=1,d,
        e=2,c,
        e>2,f)

 

Dangar332_0-1703874369190.png

 

Thanks a lot for the help!!!

Dangar332
Super User
Super User

hi, @flaviobdsti 

use Networkday() function 

Networkday() 

Thank you for the response; I had already used this function, but it was not enough to solve the problem. The thing is, the NETWORKDAYS function is a function that calculates the number of business days (working days) between two dates, excluding Saturdays and Sundays by default. However, in my case, I need to return the value in minutes and consider a specific range of working hours. With the NETWORKDAYS function alone, I haven't been able to achieve the expected result.

Hi, @flaviobdsti 

 

minute = 
 var a = NETWORKDAYS('Table (4)'[start],'Table (4)'[end])
 var starttime = FORMAT('Table (4)'[start],"hh:mm:ss")
 var endtime = FORMAT('Table (4)'[end],"hh:mm:ss")
 var _hour = LEFT(FORMAT(endtime-starttime,"hh:mm:ss"),2)*60
 var _minute = RIGHT(LEFT(FORMAT(endtime-starttime,"hh:mm:ss"),5),2)
 var _second = RIGHT(FORMAT(endtime-starttime,"hh:mm:ss"),2)
 var result = _hour +(_minute &"."&_second)
 return
 result

 

 

Dangar332_0-1703869139266.png

 

Dangar332_0-1703869196540.png

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.