Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
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
dimHoliday
Productive work interval: 08:00:00 to 17:00:00
Solved! Go to Solution.
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)
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)
Thanks a lot for the help!!!
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
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
65 | |
62 | |
51 | |
36 | |
35 |
User | Count |
---|---|
79 | |
66 | |
59 | |
45 | |
45 |