runtime
Warehouse and Reporting · milestone 05 / 06

milestone 5/6 Monthly change & cumulative reports

Measure monthly change and cumulative totals.

Warehouse and Reporting · Profile raw CRM/sales records, build Silver and Gold tables in the disposable lab, explore the fact table, and publish repeatable reporting logic.

approach

Aggregate to monthly grain before using LAG or a running SUM. A percentage change needs a nonzero prior value. This report uses observed months; a complete calendar would be required if missing months should appear as zero.

worked-example.sql
WITH monthly AS(
  SELECT strftime('%Y-%m',order_date) AS month, SUM(sales) AS sales
  FROM fact_sales
  GROUP BY month
)
SELECT
  month,
  sales,
  SUM(sales) OVER(ORDER BY month ROWS UNBOUNDED PRECEDING) AS running_sales
FROM monthly;

data for this milestone

fact_sales6 columns · 9 rows
sale_keyinteger · keycustomer_keyintegerproduct_keyintegerquantityintegersalesrealorder_datetext
1112242025-01-01
2231802025-01-02
3121452025-01-15
43422402025-02-01
54321602025-02-05

showing 5 of 9 rows

challenge 1

Return month (YYYY-MM),sales,running_sales for observed months; cumulative sales ordered by month.

Sort output by month.

what to return

Columns
monthsalesrunning_sales in this order
Rows
in the order asked
challenge-1.sql
 
3 steps left · check both queries and pass the concept checkOpen the reportNext milestone
Monthly change & cumulative reports — Warehouse and Reporting · Runtime