Weld logo
amazon-mws logo
Amazon Selling Partner API

Monthly Shipping and Delivery Reports

Generates a monthly shipping and delivery report for Amazon integration. It calculates various metrics such as the number of orders, total items shipped and unshipped, average days to ship, and the count of premium and regular orders. It also includes information on different shipping service levels and the number of orders for each level. The final result is sorted by month and shipping service level.
1with
2    MonthlyShippingPerformance as (
3        select
4            date_trunc(cast(PurchaseDate as date), month) month
5          , count(distinct AmazonOrderId) as NumberOfOrders
6          , sum(NumberOfItemsShipped) as TotalItemsShipped
7          , sum(NumberOfItemsUnshipped) as TotalItemsUnshipped
8          , avg(
9                timestamp_diff(LatestShipDate, EarliestShipDate, day)
10            ) as AvgDaysToShip
11          , sum(
12                case
13                    when IsPremiumOrder then 1
14                    else 0
15                end
16            ) as PremiumOrders
17          , sum(
18                case
19                    when not IsPremiumOrder then 1
20                    else 0
21                end
22            ) as RegularOrders
23        from
24            {{raw.amazon_selling_api_oauth.orders}}
25        group by
26            month
27    )
28  , ShippingServiceLevels as (
29        select
30            date_trunc(cast(PurchaseDate as date), month) month
31          , ShipServiceLevel
32          , count(distinct AmazonOrderId) as ServiceLevelOrders
33        from
34            {{raw.amazon_selling_api_oauth.orders}}
35        group by
36            month
37          , ShipServiceLevel
38    )
39select
40    m.Month
41  , m.NumberOfOrders
42  , m.TotalItemsShipped
43  , m.TotalItemsUnshipped
44  , m.AvgDaysToShip
45  , m.PremiumOrders
46  , m.RegularOrders
47  , s.ShipServiceLevel
48  , s.ServiceLevelOrders
49from
50    MonthlyShippingPerformance m
51    left join ShippingServiceLevels s on m.Month = s.Month
52order by
53    m.Month desc
54  , s.ShipServiceLevel;
Example of output from model:
+---------------------+----------------+-------------------+---------------------+--------------+---------------+----------------+-------------------+-------------------+
|        Month        | NumberOfOrders | TotalItemsShipped | TotalItemsUnshipped | AvgDaysToShip | PremiumOrders | RegularOrders  | ShipServiceLevel  | ServiceLevelOrders|
+---------------------+----------------+-------------------+---------------------+--------------+---------------+----------------+-------------------+-------------------+
| 2022-09-01 00:00:00 |      150       |       500         |         100         |      2.5     |      100      |      50        |    Standard       |        100        |
| 2022-09-01 00:00:00 |      150       |       500         |         100         |      2.5     |      100      |      50        |    Expedited      |        75         |
| 2022-08-01 00:00:00 |      200       |       600         |         200         |      3.2     |      150      |      50        |    Standard       |        120        |
| 2022-08-01 00:00:00 |      200       |       600         |         200         |      3.2     |      150      |      50        |    Expedited      |        80         |
+---------------------+----------------+-------------------+---------------------+--------------+---------------+----------------+-------------------+-------------------+

The Monthly Shipping and Delivery Reports SQL template is designed to provide insights into the shipping performance and service levels of Amazon orders on a monthly basis. By integrating with the Amazon Selling API, this SQL code retrieves data such as the number of orders, total items shipped and unshipped, average days to ship, premium and regular orders, and the service level of each order. The SQL code consists of two common table expressions (CTEs): MonthlyShippingPerformance and ShippingServiceLevels. The MonthlyShippingPerformance CTE calculates various metrics related to shipping performance, such as the number of orders, total items shipped and unshipped, average days to ship, and the breakdown of premium and regular orders. The ShippingServiceLevels CTE provides information on the service level of each order. The final SELECT statement combines the data from both CTEs and retrieves the desired fields, including the month, number of orders, total items shipped and unshipped, average days to ship, premium and regular orders, service level, and the number of orders for each service level. The result is ordered by month in descending order and then by the service level. This SQL template can be useful for analyzing and monitoring the shipping performance of Amazon orders over time. It allows you to identify trends, track the efficiency of order fulfillment, compare service levels, and make data-driven decisions to optimize shipping processes. The generated output from this SQL provides a comprehensive overview of the monthly shipping and delivery performance, enabling you to gain valuable insights into your Amazon business operations.

Ready to start modeling your own amazon-mws data?

Get started building your data warehouse with amazon-mws and connect all your apps and databases.

amazon-mws logo
Weld logo
Sign up for free
Weld logo

Tired of scattered data? Sync your data in minutes with our AI-powered ETL platform. Seamlessly connect all your apps, files, and databases.

Backed by leading investors
Frontline logoCherry logoInnnovation Fund logo
Twitter LogoLinkedIn Logo
GDPR logoSOC2
© 2024 Weld. All rights reserved.