Forum Discussion
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 .
I have tried running these two formulas
--------------------------------------------------------------------
----------------------------------------------
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?
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 ( 1899, 12, 30 ), dt, DAY ), "00:" )
VAR hhmmss =
FORMAT ( dt, "hh:mm:ss" )
RETURN
days & hhmmss
Pat
8 Replies
- mahoneypatMicrosoft 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 ( 1899, 12, 30 ), dt, DAY ), "00:" )
VAR hhmmss =
FORMAT ( dt, "hh:mm:ss" )
RETURN
days & hhmmss
Pat- AnonymousNot applicable
Thank you! exactly what I am looking for!
- AnonymousNot applicable
I do it as follows. I make a Divisor Measure:
Divisor = 86400Add 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 GetDayIntHour = VAR DayFrac = Divide([Total Time], [Divisor]) VAR GetHour = Hour(DayFrac) RETURN GetHourIntMin = VAR DayFrac = Divide([Total Time], [Divisor]) VAR GetMin = MINUTE(DayFrac) RETURN GetMinIntSec = VAR DayFrac = Divide([Total Time], [Divisor]) VAR GetSec = SECOND(DayFrac) RETURN GetSecThen your actual Total Duration measure will be:Total Duration = TIME([IntHour], [IntMin], [IntSec])Now you have Total Duration in h:mm:ss format.--Nate- AnonymousNot applicable
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.
- Greg_DecklerCommunity Champion
Anonymous Try Chelsie Eiden's Duration: Chelsie Eiden's Duration - Microsoft Power BI Community
- AnonymousNot applicable
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 GetDayIntHour = VAR DayFrac = Divide([Total Time], [Divisor]) VAR GetHour = Hour(DayFrac) RETURN GetHourIntMin = VAR DayFrac = Divide([Total Time], [Divisor]) VAR GetMin = MINUTE(DayFrac) RETURN GetMinIntSec = VAR DayFrac = Divide([Total Time], [Divisor]) VAR GetSec = SECOND(DayFrac) RETURN GetSecThen 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 GetHourIntMin = VAR GetMin = MINUTE([Total Time]) RETURN GetMinIntSec =VAR GetSec = SECOND([Total Time]) RETURN GetSecThen your actual Total Duration measure will be:Total Duration = TIME([IntHour], [IntMin], [IntSec])