Skip to main content

Production and cycle-time calculations

Inspect the SQL for run populations, progress, quantities and cycle-time measures.

Written by Alex Merkin

Question numbers match their folders: folder 01 contains 01-01, 01-02 and so on. The starter dashboard uses 01-05, 01-08 and 01-02; process filter values come from 01-20. OBP identities and SQL filenames remain stable.

These English-language SQL variants preserve the source calculations and inclusion rules from the 8 November 2026 snapshot. Output aliases and display-category literals are translated into English. Replace {{schema}} with your authorized schema and run one question at a time. Dashboard and viewer filters are separate.

02-01 · Production runs by status

See runs grouped as waiting, in progress or finished.

Inspection hint: Any status other than WF.NEW or WF.FINISH, including NULL, is classified as in progress. Questions 02-02,02-03,02-09 and 02-11 exclude NULL through NOT IN.

SELECT CASE status WHEN 'WF.NEW' THEN 'Waiting' WHEN 'WF.FINISH' THEN 'Finished' ELSE 'In progress' END AS "Run status",count(*) AS "Runs" FROM {{schema}}.workflowsessionitem WHERE deletedat IS NULL GROUP BY 1 ORDER BY 2 DESC;

02-02 · Work in progress by process

Compare run counts whose status is neither WF.NEW nor WF.FINISH.

Inspection hint: NOT IN also excludes missing statuses. This does not prove that work is happening at this instant.

SELECT workflowname AS "Process",count(*) AS "Runs in progress" FROM {{schema}}.workflowsessionitem WHERE deletedat IS NULL AND status NOT IN ('WF.NEW','WF.FINISH') GROUP BY 1 ORDER BY 2 DESC;

02-03 · Work in progress by next step

Locate grouped runs by process name, next reported step and next chapter.

Inspection hint: The grain is process × next step × next chapter. Identical names can merge groups; no station-entry timestamp is measured.

SELECT workflowname AS "Process",nextnodename AS "Reported next step",nextchaptername AS "Next chapter",count(*) AS "Runs" FROM {{schema}}.workflowsessionitem WHERE deletedat IS NULL AND status NOT IN ('WF.NEW','WF.FINISH') GROUP BY 1,2,3 ORDER BY 4 DESC;

02-04 · Runs waiting to start

Find individual WF.NEW runs, ordered with the oldest created records first.

Inspection hint: Quantity is not a run count. Use the run identifier to inspect an individual case.

SELECT _id AS "Run ID",workflowname AS "Process",partsku AS "SKU",created AS "Created date",quantity AS "Stock quantity" FROM {{schema}}.workflowsessionitem WHERE deletedat IS NULL AND status='WF.NEW' ORDER BY created;

02-05 · Runs completed by week

Count finished runs with an end date, grouped by completion week.

Inspection hint: Trino weeks start on Monday. A result filter selects the week-start timestamp, not individual days within that week.

SELECT date_trunc('week',"end") AS "Completion week",count(*) AS "Runs completed" FROM {{schema}}.workflowsessionitem WHERE deletedat IS NULL AND status='WF.FINISH' AND "end" IS NOT NULL GROUP BY 1 ORDER BY 1;

02-06 · Recorded quantities in finished runs by SKU

Compare finished run counts and their recorded quantities by SKU.

Inspection hint: A missing quantity does not add to SUM but its run still counts. These quantities are not independently verified good output.

SELECT partsku AS "SKU",count(*) AS "Runs",sum(quantity) AS "Recorded quantity" FROM {{schema}}.workflowsessionitem WHERE deletedat IS NULL AND status='WF.FINISH' GROUP BY 1 ORDER BY 3 DESC;

02-07 · Elapsed cycle time by process

Compare approximate median and P90 elapsed hours in finished runs with usable start and end dates.

Inspection hint: Requires start and end in the correct order. Check the measured run count and date coverage in 06-01.

SELECT workflowname AS "Process",count(*) AS "Runs",approx_percentile(date_diff('second',start,"end")/3600.0,0.5) AS "Median hours",approx_percentile(date_diff('second',start,"end")/3600.0,0.9) AS "P90 hours" FROM {{schema}}.workflowsessionitem WHERE deletedat IS NULL AND status='WF.FINISH' AND start IS NOT NULL AND "end">=start GROUP BY 1 ORDER BY 3 DESC;

02-08 · Net and elapsed time by process

Compare recorded net-time and elapsed-time medians for finished runs.

Inspection hint: Elapsed dates are validated, but net time need not be positive. NULL net values are omitted; zero or negative values can enter the median. The two medians can use different populations; check 06-05.

SELECT workflowname AS "Process",count(*) AS "Runs",approx_percentile(nettimespent/3600.0,0.5) AS "Median net hours",approx_percentile(date_diff('second',start,"end")/3600.0,0.5) AS "Median elapsed hours" FROM {{schema}}.workflowsessionitem WHERE deletedat IS NULL AND status='WF.FINISH' AND start IS NOT NULL AND "end">=start GROUP BY 1 ORDER BY 4 DESC;

02-09 · Progress of open runs

Inspect individual runs classified as in progress, their next step and recorded progress.

Inspection hint: Progress is shown as stored, without converting its scale to percentages. A start timestamp is not required.

SELECT _id AS "Run ID",workflowname AS "Process",partsku AS "SKU",progress AS "Progress",nextnodename AS "Next step",start AS "Run start" FROM {{schema}}.workflowsessionitem WHERE deletedat IS NULL AND status NOT IN ('WF.NEW','WF.FINISH') ORDER BY progress DESC;

02-10 · Runs created by month

Count runs created in each month across all current statuses.

Inspection hint: Creation does not mean a run started or finished. Current status does not reconstruct historical status.

SELECT date_trunc('month',created) AS "Creation month",count(*) AS "Runs created" FROM {{schema}}.workflowsessionitem WHERE deletedat IS NULL GROUP BY 1 ORDER BY 1;

02-11 · Runs in progress by SKU

Compare in-progress run counts by partsku.

Inspection hint: Counts runs, not SUM(quantity). Use 02-09 to inspect a specific run.

SELECT partsku AS "SKU",count(*) AS "Runs in progress" FROM {{schema}}.workflowsessionitem WHERE deletedat IS NULL AND status NOT IN ('WF.NEW','WF.FINISH') GROUP BY 1 ORDER BY 2 DESC;

06-01 · Date coverage for cycle-time calculations

Check finished runs with usable dates versus missing or reversed dates before interpreting cycle time.

Inspection hint: A zero-length duration passes this date-order condition. This is coverage, not a check of business plausibility.

SELECT workflowname AS "Process",count(*) AS "Finished runs",count_if(start IS NOT NULL AND "end">=start) AS "Measurable orders",count_if(start IS NULL OR "end" IS NULL OR "end"<start) AS "Dates to review" FROM {{schema}}.workflowsessionitem WHERE deletedat IS NULL AND status='WF.FINISH' GROUP BY 1 ORDER BY 2 DESC;

06-02 · Due-date coverage in open orders

Compare NEW and IN_PROGRESS orders with and without a recorded due date.

Inspection hint: Tests existence only, not plausibility. Frozen orders are excluded.

SELECT workflowname AS "Process",count(*) AS "Open orders",count_if(expecteddate IS NOT NULL) AS "With due date",count_if(expecteddate IS NULL) AS "Without due date" FROM {{schema}}.workorder WHERE deletedat IS NULL AND replace(statustype,'WO.STATUSES.','') IN ('NEW','IN_PROGRESS') GROUP BY 1 ORDER BY 2 DESC;

06-03 · Date coverage for on-time completion

Check closed orders with both due and completion dates versus missing information.

Inspection hint: Does not validate start or release dates or business plausibility of the timestamps.

SELECT workflowname AS "Process",count(*) AS "Closed orders",count_if("end" IS NOT NULL AND expecteddate IS NOT NULL) AS "Measurable orders",count_if("end" IS NULL OR expecteddate IS NULL) AS "Missing data" FROM {{schema}}.workorder WHERE deletedat IS NULL AND replace(statustype,'WO.STATUSES.','')='END' GROUP BY 1 ORDER BY 2 DESC;

02-12 · Waiting time before work starts

Compare approximate median days from release to work start by process.

Inspection hint: Missing release falls back to creation. Unlike 01-11, the source does not require END status; an already-started open order can qualify.

SELECT workflowname AS "Process",count(*) AS "Orders measured",approx_percentile(date_diff('hour',coalesce(releasedat,createdat),start)/24.0,0.5) AS "Median waiting days",count_if(releasedat IS NULL) AS "Calculated from creation" FROM {{schema}}.workorder WHERE deletedat IS NULL AND start>=coalesce(releasedat,createdat) GROUP BY 1 ORDER BY 3 DESC;

01-13 · Planned and reported quantities by SKU

Compare planned, reported good and reported rejected quantities across all work-order statuses.

Inspection hint: The three totals come from different fields. Good plus rejected is not enforced to equal planned quantity. Check units and reporting rules.

SELECT sku AS "SKU",count(*) AS "Orders",sum(quantity) AS "Planned quantity",sum(validquantity) AS "Reported good quantity",sum(invalidquantity) AS "Reported rejected quantity" FROM {{schema}}.workorder WHERE deletedat IS NULL GROUP BY 1 ORDER BY 2 DESC;

02-13 · Finished runs by process

Count all runs marked WF.FINISH by process.

Inspection hint: Includes missing end dates. Totals can exceed 02-05 or 02-07, which require suitable completion dates.

SELECT workflowname AS "Process",count(*) AS "Finished runs" FROM {{schema}}.workflowsessionitem WHERE deletedat IS NULL AND status='WF.FINISH' GROUP BY 1 ORDER BY 2 DESC;

06-05 · Positive net-time coverage in finished runs

Compare finished runs with positive net time against missing, zero or negative net time.

Inspection hint: The population is all finished runs, not exactly the elapsed-date-valid population of 02-08. Positive does not certify accuracy.

SELECT workflowname AS "Process",count(*) AS "Finished runs",count_if(nettimespent>0) AS "With positive net time",count_if(nettimespent IS NULL OR nettimespent<=0) AS "Without positive net time" FROM {{schema}}.workflowsessionitem WHERE deletedat IS NULL AND status='WF.FINISH' GROUP BY 1 ORDER BY 2 DESC;

02-14 · Finished runs: time details

Inspect individual finished runs and their recorded net and calculated elapsed hours.

Inspection hint: All WF.FINISH runs remain visible. Elapsed hours are blank for missing or reversed dates; net hours are shown separately without a positivity test.

SELECT _id AS "Run ID",workflowname AS "Process",partsku AS "SKU",start AS "Run start","end" AS "Run end",CASE WHEN "end">=start THEN date_diff('second',start,"end")/3600.0 END AS "Elapsed hours",nettimespent/3600.0 AS "Net hours" FROM {{schema}}.workflowsessionitem WHERE deletedat IS NULL AND status='WF.FINISH' ORDER BY "end" DESC;

Related articles

Did this answer your question?