Skip to main content
Question

MTTA and MTTR

  • July 13, 2026
  • 1 reply
  • 29 views

secfmari

I'm trying to calculate mttr and mtta per environment; this metric is important for each existing environment. Does anyone know how I can do this in the case_history table?

I notice that the `cases` table contains the `cases.environment` field. Is it possible to perform this calculation using that table?

MMTR:

 

stage stage1{
$case_id = case_history.case_response_platform_info.case_id
match:
    $case_id
outcome:
    $case_close_time = max(if(case_history.case_activity = "CLOSE_CASE", case_history.event_time.seconds, 0))
    $status = array_distinct(case_history.case_activity)
    $TTC = $case_close_time - min(case_history.event_time.seconds)
condition:
    arrays.contains($status, "CREATE_CASE") and arrays.contains($status, "CLOSE_CASE")
    
    }
outcome:
    $case_count = count($stage1.case_id)
    $MTTC = (math.round(avg($stage1.TTC)/60))

MTTA:

stage stage1{
$case_id = case_history.case_response_platform_info.case_id
match:
    $case_id
outcome:
    $case_assign_time = min(if(case_history.case_activity = "ASSIGNEE_CHANGE", case_history.event_time.seconds, 9999999999999999))
    $status = array_distinct(case_history.case_activity)
    $TTA = $case_assign_time - min(case_history.event_time.seconds)
    
condition:
    arrays.contains($status, "CREATE_CASE") and arrays.contains($status, "ASSIGNEE_CHANGE") 
    }
outcome:
    $case_count = count($stage1.case_id)
    $MTTA = (math.round((avg($stage1.TTA)/60)))

1 reply

hliu
Forum|alt.badge.img+5
  • Bronze 3
  • July 13, 2026

MTTR / MTTC assuming case last update time is the case closed time:

stage stage1 {
case.name != ""
case.status="CLOSED"
$caseid=case.name
$env=case.environment
match: $env, $caseid
outcome:
$case_close_time = max(if(case.status="CLOSED", case.update_time.seconds, 0)) //assuming case last update time is the case closed time
$TTC = $case_close_time - min(case.create_time.seconds)
$status = array_distinct(case.status)
}
$root_env=$stage1.env
match: $root_env
outcome:
$case_count = count($stage1.caseid)
$MTTC = (math.round(avg($stage1.TTC)/60))


For MTTA grouped by environment, as you’ve already realized:
the environment field is located in the case table, while to get the timestamp of the 1st ASSIGNEE_CHANGE we need to use the case_history table.
So we’d need to join them by a common key, e.g.:

$h.case_history.case_response_platform_info.case_id = $case_id
$c.case.response_platform_info.response_platform_id = $case_id

unfortunately it looks like there is a flag/switch to join these 2 specific case tables, and I don’t have it enabled in my environment:


you could try asking Google to enable that flag for you. Once enabled, a possible join of the 2 tables to calculate MTTA split by environment could look like below (beware it is untested, as I don’t have the required flag to run it):

stage stage1 {
$case_id = case_history.case_response_platform_info.case_id
match:$case_id
outcome:
$case_assign_time = min(if(case_history.case_activity = "ASSIGNEE_CHANGE", case_history.event_time.seconds, 9999999999 ))
$status = array_distinct(case_history.case_activity)
$TTA = $case_assign_time - min(case_history.event_time.seconds)
condition:arrays.contains($status, "CREATE_CASE") and arrays.contains($status, "ASSIGNEE_CHANGE")
}
case.name != ""
$env=case.environment
$caseid = case.response_platform_info.response_platform_id
left join $caseid = $stage1.case_id
match: $env
outcome:
$assigned_case_count = count_distinct($stage1.case_id)
$total_case_count = count_distinct($caseid)
$MTTA = (math.round((avg($stage1.TTA)/60)))