Product returns by month
Units shipped and units returned per SKU per month, for return rates by product.
- Grain
- month x shiphero_account x account_id x sku
- Built from
- 5Raw tables
- 5Staging
- 1Core
- 1Analytics
- Reads from ShipHero
- orderorder_line_itemproductreturnreturn_line_item
- Ships as
- Weld and dbt SQL, open source on GitHub
1-- core.shiphero.product_returns_by_month
2-- Units shipped and units returned per SKU per month, for return rates by product.
3-- Grain: month x shiphero_account x account_id x sku.
4-- Depends on: staging.shiphero.order, .order_line_item, .return,
5-- .return_line_item, .product
6--
7-- SHIPPED units land on the month the ORDER was placed (order_line_item carries
8-- quantity_shipped but no ship date). RETURNED units land on the month the RETURN
9-- was created. A return rate over a single month therefore compares returns of
10-- earlier orders with this month's shipments; read it over a quarter or longer,
11-- or accept the lag.
12--
13-- Returned units come from return_line_item, which identifies the product by
14-- product_id; the SKU is resolved through the product table. A return line whose
15-- product is not synced lands under a NULL sku rather than being dropped.
16--
17-- Received and restocked counts lag: returns are picked up by creation date,
18-- so items received after the return's period was synced keep their old counts
19-- until it is re-synced.
20--
21-- account_id is the ShipHero account that owns the order or return. For a 3PL it
22-- is the brand, and it is in the grain because two brands can use the same SKU
23-- string for different products.
24--
25-- Built on a month spine per SKU, from the SKU's first activity to the current
26-- month, so a SKU with no returns in a month returns zeros.
27
28WITH shipped AS (
29 SELECT
30 DATE_TRUNC(DATE(COALESCE(o.order_date, o.created_at)), MONTH) AS month,
31 li.shiphero_account,
32 o.account_id,
33 li.sku,
34 ANY_VALUE(li.product_name) AS product_name,
35 SUM(li.quantity) AS units_ordered,
36 SUM(li.quantity_shipped) AS units_shipped
37 FROM {{staging.shiphero.order_line_item}} li
38 JOIN {{staging.shiphero.order}} o
39 ON o.shiphero_account = li.shiphero_account
40 AND o.order_id = li.order_idThis model and the 6 it depends on. Deploy them together; refs like {{staging.…}} resolve to the matching folders in Weld, and the dbt view uses source() and ref().
How it counts. And where it stops.
SHIPPED units land on the month the ORDER was placed (order_line_item carries quantity_shipped but no ship date). RETURNED units land on the month the RETURN was created. A return rate over a single month therefore compares returns of earlier orders with this month's shipments; read it over a quarter or longer, or accept the lag. Returned units come from return_line_item, which identifies the product by product_id; the SKU is resolved through the product table. A return line whose product is not synced lands under a NULL sku rather than being dropped. Received and restocked counts lag: returns are picked up by creation date, so items received after the return's period was synced keep their old counts until it is re-synced. account_id is the ShipHero account that owns the order or return. For a 3PL it is the brand, and it is in the grain because two brands can use the same SKU string for different products. Built on a month spine per SKU, from the SKU's first activity to the current month, so a SKU with no returns in a month returns zeros.
Raw tables it reads
- raw.shiphero.order
- raw.shiphero.order_line_item
- raw.shiphero.product
- raw.shiphero.return
- raw.shiphero.return_line_item
More ShipHero models
Put ShipHero in front
of your agents.
Connect ShipHero, deploy the models, and ask questions in Claude, Cursor or ChatGPT. Free for 14 days, no credit card.