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

How do I calculate time in Power BI?

I have been trying to create a measure that will accruately show me the time per person in Power BI related to talk time. So calcualting how much each person has for talk time but the formulas I am trying keep giving me the wrong answer. I am trying to caluclate the total talk time and then add each "Agent Name"(column with all agents) and show what each agents talk time is.

I have the column (BILL TIME)in power query already set to duration which shows the correct duration .
Screenshot_1.png
I have tried running these two formulas

Total Talk Time = SUM(data[BILL TIME])



String Duration in Hours and Minutes =
var vMinues=[Total Talk Time]
var vHours=int( vMinues/60)
var vRemainingMinutes=MOD(vMinues, 60)
return
vHours&" Hours & "& vRemainingMinutes& " Minutes"
--------------------------------------------------------------------
TimeCosts =
VAR total =
SUM ( data[BILL TIME] )
VAR hours =
INT ( total / 3600 )
VAR minutes =
INT ( MOD ( total, 3600 ) / 60 )
VAR seconds =
MOD ( MOD ( total, 3600 ), 60 )
RETURN
hours & " hours "
& minutes
& " minutes "
& seconds
& " seconds"

----------------------------------------------

talk_time = VAR Elapsed_Time = SELECTEDVALUE(data[BILL TIME ])

VAR days = INT(Elapsed_Time)

VAR _hrs = (Elapsed_Time - days) = 24

VAR hrs = INT(_hrs)

VAR mins = ROUND((_hrs - hrs) * 60,0)

Return

days & " d " & FORMAT(hrs,"00") & " h " & FORMAT(mins,"00") & " m "

any other way I can do this?



1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

Another approach you can try (if your total duration is <24 hrs) is an expression like this.

 

Total CallTime =
FORMAT ( CONVERT ( SUM ( CallTime[CallTime] )DATETIME )"hh:mm:ss" )
 
If the total is >24 hrs, you can use this expression.
 
 
Total CallTime =
VAR dt =
    CONVERT ( SUM ( CallTime[CallTime] )DATETIME )
VAR days =
    FORMAT ( DATEDIFF ( DATE ( 18991230 )dtDAY )"00:" )
VAR hhmmss =
    FORMAT ( dt"hh:mm:ss" )
RETURN
    days & hhmmss
 
Pat
 




Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

8 REPLIES 8
mahoneypat
Employee
Employee

Another approach you can try (if your total duration is <24 hrs) is an expression like this.

 

Total CallTime =
FORMAT ( CONVERT ( SUM ( CallTime[CallTime] )DATETIME )"hh:mm:ss" )
 
If the total is >24 hrs, you can use this expression.
 
 
Total CallTime =
VAR dt =
    CONVERT ( SUM ( CallTime[CallTime] )DATETIME )
VAR days =
    FORMAT ( DATEDIFF ( DATE ( 18991230 )dtDAY )"00:" )
VAR hhmmss =
    FORMAT ( dt"hh:mm:ss" )
RETURN
    days & hhmmss
 
Pat
 




Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thank you! exactly what I am looking for!

watkinnc
Super User
Super User

Sorry! I see your values are already decimal...in other words, already divided by 86400. This greatly simplifies the whole thing:

 

Add a total time measure:
 
TotalTime =  SUM(data[BILL TIME])
 
Then 4 measures each for day part, hour part, minute part, and second part:
 
IntDay = VAR DayFrac = Divide(Day([Total Time], [Divisor]) VAR GetDay = Day(DayFrac) RETURN GetDay
 
IntHour = VAR DayFrac = Divide([Total Time], [Divisor]) VAR GetHour = Hour(DayFrac) RETURN GetHour
 
IntMin = VAR DayFrac = Divide([Total Time], [Divisor]) VAR GetMin = MINUTE(DayFrac) RETURN GetMin
 
IntSec = VAR DayFrac = Divide([Total Time], [Divisor]) VAR GetSec = SECOND(DayFrac) RETURN GetSec
 
Then your actual Total Duration measure will be:
 
Total Duration = TIME([IntHour], [IntMin], [IntSec])
 
TotalTime =  SUM(data[BILL TIME])
 
Then 4 measures each for day part, hour part, minute part, and second part:
 
IntHour = VAR GetHour = Hour([Total Time]) RETURN GetHour
 
IntMin = VAR GetMin = MINUTE([Total Time]) RETURN GetMin
 
IntSec =VAR GetSec = SECOND([Total Time]) RETURN GetSec
 
Then your actual Total Duration measure will be:
 
Total Duration = TIME([IntHour], [IntMin], [IntSec])
 

I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
watkinnc
Super User
Super User

I do it as follows.  I make a Divisor Measure:

 

Divisor = 86400
 
Add a total time measure:
 
TotalTime =  SUM(data[BILL TIME])
 
Then 4 measures each for day part, hour part, minute part, and second part:
 
IntDay = VAR DayFrac = Divide([Total Time], [Divisor]) VAR GetDay = Day(DayFrac) RETURN GetDay
 
IntHour = VAR DayFrac = Divide([Total Time], [Divisor]) VAR GetHour = Hour(DayFrac) RETURN GetHour
 
IntMin = VAR DayFrac = Divide([Total Time], [Divisor]) VAR GetMin = MINUTE(DayFrac) RETURN GetMin
 
IntSec = VAR DayFrac = Divide([Total Time], [Divisor]) VAR GetSec = SECOND(DayFrac) RETURN GetSec
 
Then your actual Total Duration measure will be:
 
Total Duration = TIME([IntHour], [IntMin], [IntSec])
 
Now you have Total Duration in h:mm:ss format.
 
--Nate

I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

Hey Nate, tried out your steps and I dont beleive it is working. this is the result I am getting for one person when it shuld my multiple hours.
Screenshot_2.png

thanks nate, tried out those steps but dont believe its working unless I am doing something wrong 
Screenshot_3.png

 

@Johnny-Mclawdog Try Chelsie Eiden's Duration: Chelsie Eiden's Duration - Microsoft Power BI Community


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

anyway that breaks it up into hours minutes seconds to be able to add all together?

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.

Top Solution Authors
Top Kudoed Authors