Forum Discussion
Median Response Time
Hi all,
I am calculating median response times from a duration variable and I have created a new column to convert that into seconds as follows:
Response Sec =
VAR AttendedDateTime = TIME(HOUR('Response Details'[AttendedTime]), MINUTE('Response Details'[Attended Time]), SECOND('Response Details'[Attended Time]))
VAR Hours = HOUR(AttendedDateTime)
VAR Minutes = MINUTE(AttendedDateTime)
VAR Seconds = SECOND(AttendedDateTime)
RETURN
Hours * 3600 + Minutes * 60 + Seconds
Third priority median YTD =
VAR MED_Response =
DIVIDE(
CALCULATE(
MEDIAN('Response Details'[Response Sec]),
DATESYTD('Response Details'[Created Date], "03/31"),
'Response Details'[Grade] = "Third Priority"
),
86400,
BLANK()
)
VAR days = INT(MED_Response)
VAR _hrs = (MED_Response - days) * 24
VAR hrs = INT(_hrs)
VAR _mins = ROUNDUP((_hrs - hrs) * 60, 2)
VAR mins = INT(_mins)
VAR secs = INT((_mins - mins) * 60)
RETURN
//days & " d " &
FORMAT(hrs, "00") & ":" & FORMAT(mins, "00") & ":" & FORMAT(secs, "00")
Hi Greg_Deckler ,
I came up with a solution, apparently the [response sec] was the part causing an issue. I am not using a [start time] and [end time] to calculate the time taken, the [attended time] is a decimal time value in the database, so I needed to re-write the [response sec] to better reflect the data type. I have referenced it below in case others need this solution:
Response Sec =
VAR DecimalValue = 'Response Details'[Attended Time]
VAR DecimalSeconds = [Attended Time] * 86400 // Convert decimal to seconds (86400 seconds in a day)
RETURN
ROUND(DecimalSeconds, 0) // Round the result to the nearest whole secondThanks
2 Replies
- Greg_DecklerCommunity Champion
randomanalyst Perhaps providing some sample data would help. Maybe you are running into an issue where the duration spans 2 days and that is causing the issue? For example, it starts on 8/13/2023 at 7PM and shows up at 5AM the next day?
- randomanalystNew Member
Hi Greg_Deckler ,
I came up with a solution, apparently the [response sec] was the part causing an issue. I am not using a [start time] and [end time] to calculate the time taken, the [attended time] is a decimal time value in the database, so I needed to re-write the [response sec] to better reflect the data type. I have referenced it below in case others need this solution:
Response Sec =
VAR DecimalValue = 'Response Details'[Attended Time]
VAR DecimalSeconds = [Attended Time] * 86400 // Convert decimal to seconds (86400 seconds in a day)
RETURN
ROUND(DecimalSeconds, 0) // Round the result to the nearest whole secondThanks