Project Hub

Project · Retail sales warehouse

One warehouse for sales, suppliers and departments

The problem

Sales, seller and product data sit in separate exports, so every report starts by cleaning the same exports again, and teams reach different totals.

The solution

A pipeline that loads every order, item, seller and review into a six-layer warehouse: dbt cleans the data, applies the late rules and builds the star schema that feeds a Power BI sales, supplier and late-delivery report.

How it works

  • Collect: Orders, items, sellers and reviews loaded as-is into Bronze
  • Clean: dbt Silver models set types, tidy names, keep one review per order
  • Rules: Gold flags late orders and ranks sellers by late items
  • Model: Semantic: a star of order facts with product, seller, customer and date
  • Report: Power BI sales, supplier and late-delivery pages

A closer look

Pipeline diagram, left to right through six layers: load.py loads seven input files as text into the Bronze layer, refused rows to bronze.quarantine; dbt builds seven Silver views, the Gold tables order_delivery and seller_late_rank, the Semantic layer's fact_order_items and four dimensions, and three Analytical views; the notebook and Power BI in the Reporting layer read the Semantic and Analytical layers only.
How the input files become the warehouse, layer by layer.
The warehouse in six layers, left to right: the Bronze layer holds the 7 input files as text with their file, row and run id (446,875 rows, 0 in quarantine); the Silver layer types and cleans them in 7 views; the Gold layer applies the rules, late orders and the seller late rank (99,441 orders, 3,095 sellers); the Semantic layer is the star schema (112,650 order items, 4 dimensions built from Silver and Gold); the Analytical layer has 3 summary views; the Reporting layer is the notebook and Power BI.
Each layer only reads the one before it.
Data flow: one box per step, in run order, from the input files to the report.
The steps, in run order.
The Semantic layer's star schema: one fact table of 112,650 order items joined to four dimensions of 99,441 customers, 3,095 sellers, 32,951 products and 1,096 dates; the late flags and the seller late rank come from Gold-layer rules.
The Semantic layer: one fact table, four dimensions.
dbt lineage, left to right: 7 Bronze sources feed 7 Silver views; the Gold layer builds order_delivery and seller_late_rank from Silver; the Semantic layer builds fact_order_items and dim_seller from Silver and Gold, and dim_product, dim_customer and dim_date from Silver; the 3 Analytical views read the fact, dim_date and dim_seller.
How dbt builds each table.
Chart: the running share of all late items by seller, most late first; 100 of 3,095 sellers cause 50% of late items.
100 sellers, half the late items.
Chart: the average review is 4.29 out of 5 for orders delivered on time and 2.27 for late ones.
Late orders score 2.27 against 4.29.

The code

ranked = sellers.sort_values("late_rank").reset_index(drop=True)
cum = ranked.late_items.cumsum() / ranked.late_items.sum()
share = numbers["top sellers: share of late items"] * 100
fig, ax = plt.subplots(figsize=(8, 3.6))
ax.plot(range(1, len(cum) + 1), cum * 100, color=ACCENT, lw=2)
ax.axvline(TOP_N, color=GREY, ls="--", lw=1)
ax.set_xlabel("Sellers, most late items first")
ax.set_ylabel("Share of all late items (%)")
analysis/analysis.ipynb

The impact

  • One star schema for sales, suppliers, products and departments.
  • The 100 suppliers to call first: 41.6% of items, half of the late ones.
  • Power BI pages on one trusted model.

The result

99,441 orders in one star schema: 100 of 3,095 sellers account for half of all late-delivered items.

Built with

  • PostgreSQL
  • dbt
  • Python
  • Docker
  • Power BI