Jira Time in Status & Cycle Time in Snowflake SQL

Measuring workflow bottlenecks and engineering cycle time in Snowflake requires clean, contiguous status transition intervals rather than raw, paginated Jira changelog arrays. This guide explains how Snowflake CDC Connector for Jira builds "STATUS_DURATIONS" automatically inside Atlassian Forge and provides four SQL templates you can run directly in Snowsight.


Why Raw Jira Changelogs Break Manual SQL Pipelines

Querying Jira REST changelogs with hand-written JSON parsing or dbt flattening scripts usually fails in two real-world scenarios:

  1. Inline Changelog Truncation: Jira Cloud's issue search endpoint only includes the most recent changelog items inline. Older status transitions on long-lived epics or incidents require paginated /rest/api/3/issue/{id}/changelog lookups ordered chronologically from startAt=0.
  2. Project Transfers Break ISSUE_KEY Joins: When a ticket moves from project OPS to ENG, its ISSUE_KEY changes permanently while its numeric ISSUE_ID stays constant. Joining changelog tables on ISSUE_KEY silently orphans historical status dwell time.

Snowflake CDC Connector for Jira handles both problems in Atlassian Forge before writing to Snowflake: it paginates issue changelogs up to 2,000 history items per issue, reconstructs chronological intervals, and keys every row by permanent ISSUE_ID.


How "STATUS_DURATIONS" Models Every Transition

Each row in "RAW_JIRA"."PUBLIC"."STATUS_DURATIONS" represents one continuous stay inside a Jira workflow status:

ColumnTypeMeaning
"DURATION_ID"VARCHAR(255)Deterministic primary key (${ISSUE_ID}:${SEQUENCE_ORDER})
"ISSUE_ID"VARCHAR(64)Permanent Jira numeric ID (always join to "ISSUES_CURRENT"."ISSUE_ID")
"ISSUE_KEY"VARCHAR(64)Current Jira issue key at sync time
"PROJECT_KEY"VARCHAR(64)Current Jira project key
"STATUS_NAME"VARCHAR(255)Workflow status name (e.g., In Progress, In Review, QA)
"STATUS_CATEGORY"VARCHAR(128)Jira status category (To Do, In Progress, Done)
"SEQUENCE_ORDER"NUMBER(10, 0)1-based chronological step number for the issue
"ENTERED_AT"TIMESTAMP_TZ(6)Timestamp when the ticket entered this status
"EXITED_AT"TIMESTAMP_TZ(6)Timestamp when the ticket left this status (NULL if active)
"DURATION_SECONDS"NUMBER(18, 3)Elapsed seconds in this status (NULL while IS_CURRENT = TRUE)
"IS_CURRENT"BOOLEANTRUE for the ticket's active status row, FALSE for completed steps
"TRANSITION_AUTHOR_ACCOUNT_ID"VARCHAR(255)Atlassian accountId of the user who triggered entry into this step

1. P50 and P90 Cycle Time by Project and Issue Type

Measure median (P50) and tail (P90) hours spent in active engineering statuses across completed workflow steps. Replace "RAW_JIRA"."PUBLIC" if you configured a different target database or schema.

SQL
SELECT
  i."PROJECT_KEY",
  i."ISSUE_TYPE",
  d."STATUS_NAME",
  COUNT(DISTINCT d."ISSUE_ID") AS issues_measured,
  ROUND(AVG(d."DURATION_SECONDS") / 3600.0, 2) AS avg_hours,
  ROUND(MEDIAN(d."DURATION_SECONDS") / 3600.0, 2) AS p50_hours,
  ROUND(PERCENTILE_CONT(0.90) WITHIN GROUP (ORDER BY d."DURATION_SECONDS") / 3600.0, 2) AS p90_hours
FROM "RAW_JIRA"."PUBLIC"."STATUS_DURATIONS" d
JOIN "RAW_JIRA"."PUBLIC"."ISSUES_CURRENT" i
  ON i."ISSUE_ID" = d."ISSUE_ID"
WHERE LOWER(d."STATUS_NAME") IN ('in progress', 'in development', 'in review', 'qa')
  AND d."DURATION_SECONDS" IS NOT NULL
GROUP BY 1, 2, 3
ORDER BY 1, 2, p50_hours DESC;

2. Live Bottleneck Queue (IS_CURRENT = TRUE)

Because EXITED_AT and DURATION_SECONDS stay NULL while an issue sits in its active workflow step, query d."IS_CURRENT" = TRUE with DATEDIFF('second', d."ENTERED_AT", CURRENT_TIMESTAMP()) to catch stalled work immediately:

SQL
SELECT
  i."ISSUE_KEY",
  i."PARENT_KEY",
  i."EPIC_KEY",
  i."SUMMARY",
  d."STATUS_NAME" AS current_status,
  d."ENTERED_AT",
  ROUND(DATEDIFF('second', d."ENTERED_AT", CURRENT_TIMESTAMP()) / 86400.0, 1) AS days_in_status,
  COALESCE(i."ASSIGNEE_DISPLAY_NAME", i."ASSIGNEE_ACCOUNT_ID") AS assignee
FROM "RAW_JIRA"."PUBLIC"."STATUS_DURATIONS" d
JOIN "RAW_JIRA"."PUBLIC"."ISSUES_CURRENT" i
  ON i."ISSUE_ID" = d."ISSUE_ID"
WHERE d."IS_CURRENT" = TRUE
  AND UPPER(i."STATUS_CATEGORY") <> 'DONE'
ORDER BY days_in_status DESC
LIMIT 25;
Tip: Enable Include assignee & reporter display names in ISSUES_CURRENT on the Projects & Fields tab in Jira Administration so ASSIGNEE_DISPLAY_NAME populates directly instead of showing an Atlassian UUID.

3. Code Review and QA Rework Detection

Count how many times tickets bounced back into In Progress, In Review, or QA by grouping "STATUS_DURATIONS" per ISSUE_ID and status:

SQL
SELECT
  i."PROJECT_KEY",
  i."EPIC_KEY",
  i."ISSUE_KEY",
  d."STATUS_NAME",
  COUNT(*) AS entries_into_status,
  ROUND(SUM(COALESCE(d."DURATION_SECONDS", DATEDIFF('second', d."ENTERED_AT", CURRENT_TIMESTAMP()))) / 3600.0, 2) AS total_hours_in_status
FROM "RAW_JIRA"."PUBLIC"."STATUS_DURATIONS" d
JOIN "RAW_JIRA"."PUBLIC"."ISSUES_CURRENT" i
  ON i."ISSUE_ID" = d."ISSUE_ID"
GROUP BY 1, 2, 3, 4
HAVING COUNT(*) > 1
ORDER BY entries_into_status DESC, total_hours_in_status DESC
LIMIT 50;

4. End-to-End Lead Time vs. Active Engineering Time per Epic

Contrast total wall-clock hours from ticket creation to resolution against active engineering status hours rolled up via i."EPIC_KEY":

SQL
WITH active_touch AS (
  SELECT
    d."ISSUE_ID",
    SUM(COALESCE(d."DURATION_SECONDS", 0)) / 3600.0 AS active_hours
  FROM "RAW_JIRA"."PUBLIC"."STATUS_DURATIONS" d
  WHERE UPPER(d."STATUS_CATEGORY") = 'IN PROGRESS'
    AND d."DURATION_SECONDS" IS NOT NULL
  GROUP BY 1
)
SELECT
  COALESCE(i."EPIC_KEY", '(No Epic)') AS epic_key,
  COUNT(DISTINCT i."ISSUE_ID") AS resolved_issues,
  COALESCE(SUM(i."STORY_POINTS"), 0) AS delivered_points,
  ROUND(MEDIAN(DATEDIFF('second', i."CREATED_AT", i."RESOLVED_AT") / 3600.0), 1) AS median_lead_hours,
  ROUND(MEDIAN(COALESCE(a.active_hours, 0)), 1) AS median_active_touch_hours
FROM "RAW_JIRA"."PUBLIC"."ISSUES_CURRENT" i
LEFT JOIN active_touch a
  ON a."ISSUE_ID" = i."ISSUE_ID"
WHERE i."RESOLVED_AT" IS NOT NULL
GROUP BY 1
ORDER BY resolved_issues DESC;

Next Steps