lesson 74 Warehouse & reporting projects · advanced
EDA: explore before telling the story
Explore distributions and relationships before reporting.
the idea
Start with schema, dimension categories, date coverage, measures, and grain. COUNT(DISTINCT sale_key) counts sales lines in this model, not a missing order-header identifier. Define what a metric counts before putting it into a report.
tables in this lesson
The challenges use this data. Each column shows its type underneath; → marks a link to another table.
fact_sales6 columns · 9 rows
| sale_keyinteger · key | customer_keyinteger | product_keyinteger | quantityinteger | salesreal | order_datetext |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 2 | 24 | 2025-01-01 |
| 2 | 2 | 3 | 1 | 80 | 2025-01-02 |
| 3 | 1 | 2 | 1 | 45 | 2025-01-15 |
| 4 | 3 | 4 | 2 | 240 | 2025-02-01 |
| 5 | 4 | 3 | 2 | 160 | 2025-02-05 |
showing 5 of 9 rows
example
The idea in one query. Press Run to see what it returns; running examples never affects your progress.
SELECT MIN(order_date) AS first_sale, MAX(order_date) AS last_sale, COUNT(*) AS sales_lines, SUM(sales) AS total_sales FROM fact_sales;
Watch for: Sales-line count and order count are different when an order contains several lines.
build it step by step
Each step changes one thing. Run them in order and watch the result change.
Look at one sales line. Each fact_sales row is one sales line. Decide that before you count or sum.
step-1.sqlSELECT sale_key, customer_key, quantity, sales, order_date FROM fact_sales LIMIT 8;
Run the reference. Start with schema, dimension categories, date coverage, measures, and grain. COUNT(DISTINCT sale_key) counts sales lines in this model, not a missing order-header identifier. Define what a metric counts before putting it into a report.
step-2.sqlSELECT MIN(order_date) AS first_sale, MAX(order_date) AS last_sale, COUNT(*) AS sales_lines, SUM(sales) AS total_sales FROM fact_sales;