Logistics & Transportation Analytics · Mission 8 of 30Medium

On-time delivery rate by carrier

Calculate OTD rate using CASE WHEN inside AVG for a conditional percentage

The Brief

Maya ChenLogistics Analystlogistics-ops

Now for the real scorecard. Join `fact_shipments` to `dim_carriers`. For delivered shipments only, compute OTD rate per carrier: a shipment is on-time if `actual_delivery_date <= planned_delivery_date`. Label the rate `otd_rate`, round to 4 decimal places. Include `carrier_name` and `total_delivered`. Sort by otd_rate ascending so worst performers are first.

You'll practice

CASE WHENJOINORDER BY

Tables & columns available

fact_shipmentsfact15 columns
ColumnTypeKey
shipment_idINTPK
carrier_idINTFK → dim_carriers
lane_idINTFK → dim_lanes
planned_pickup_dateTEXT
actual_pickup_dateTEXT
planned_delivery_dateTEXT
actual_delivery_dateTEXT
qty_orderedINT
qty_shippedINT
weight_lbsREAL
freight_costREAL
fuel_surchargeREAL
accessorial_costREAL
dwell_hours_at_originREAL
statusTEXT
dim_carriersdim6 columns
ColumnTypeKey
carrier_idINTPK
carrier_nameTEXT
scacTEXT
modeTEXT
on_time_target_pctREAL
hq_stateTEXT

Hints (3)

Each hint you reveal reduces the XP you can earn. Try the query first.

Hint 1

Filter to status = 'delivered' before computing OTD — in_transit and failed shipments have no valid final delivery date.

Hint 2

Conditional aggregation: turn a boolean (was-on-time) into 1.0/0.0 inside an aggregate to compute a rate.

Hint 3

GROUP BY carrier_name, sort by otd_rate ASC so worst performers float to the top.