runtime
74 / 88

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 · keycustomer_keyintegerproduct_keyintegerquantityintegersalesrealorder_datetext
1112242025-01-01
2231802025-01-02
3121452025-01-15
43422402025-02-01
54321602025-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.

example.sql
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.

  1. Look at one sales line. Each fact_sales row is one sales line. Decide that before you count or sum.

    step-1.sql
    SELECT sale_key, customer_key, quantity, sales, order_date
    FROM fact_sales
    LIMIT 8;
  2. 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.sql
    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;

challenge 1

Return first_sale, last_sale, sales_lines and total_sales as one summary row from fact_sales.

Return first_salelast_salesales_linestotal_salesany row order

challenge-1.sql
 
To master this lesson, solve both challenges without hints and pass the concept check. 3 of 3 to go.