runtime
74 / 88

lesson 74 Warehouse & reporting projects · advanced

EDA: explore before telling the story

Explore distributions and relationships before reporting.

the idea

Exploratory data analysis (EDA) checks the shape of the data before reporting on it: the date range, the number of rows, totals of the main measures and how many entities are active. These numbers become the reference points every later report must agree with.

Dataset: Retail

The tables the challenges use, with their first 6 rows. Under each column name: the kind of value it holds, and which table it links to.

fact_sales7 columns · 45,151 rows
sale_keynumber · unique idorder_idnumbercustomer_keynumber · links to dim_customerproduct_keynumber · links to dim_productorder_datedatequantitynumbersalesdecimal
65625367955620622011-01-04834
6562636795568812011-01-0417.95
6562736795568872011-01-0414.95
6562836795564012011-01-0425.9
65629367955640592011-01-043630.6
65630367955643012011-01-041029.5
sale_keynumber · unique id
65625
order_idnumber
3679
customer_keynumber · links to dim_customer
556
product_keynumber · links to dim_product
2062
order_datedate
2011-01-04
quantitynumber
8
salesdecimal
34
sale_keynumber · unique id
65626
order_idnumber
3679
customer_keynumber · links to dim_customer
556
product_keynumber · links to dim_product
881
order_datedate
2011-01-04
quantitynumber
1
salesdecimal
7.95
sale_keynumber · unique id
65627
order_idnumber
3679
customer_keynumber · links to dim_customer
556
product_keynumber · links to dim_product
887
order_datedate
2011-01-04
quantitynumber
1
salesdecimal
4.95
sale_keynumber · unique id
65628
order_idnumber
3679
customer_keynumber · links to dim_customer
556
product_keynumber · links to dim_product
401
order_datedate
2011-01-04
quantitynumber
2
salesdecimal
5.9
sale_keynumber · unique id
65629
order_idnumber
3679
customer_keynumber · links to dim_customer
556
product_keynumber · links to dim_product
4059
order_datedate
2011-01-04
quantitynumber
36
salesdecimal
30.6
sale_keynumber · unique id
65630
order_idnumber
3679
customer_keynumber · links to dim_customer
556
product_keynumber · links to dim_product
4301
order_datedate
2011-01-04
quantitynumber
10
salesdecimal
29.5

first 6 of 45,151 rows · your queries use all of them

customers4 columns · 848 rows
customer_idnumber · unique idcountrytextregiontextfirst_order_atdate & time
12347IcelandEurope2010-10-31 14:20:00
12353BahrainRest of World2010-10-27 12:44:00
12359CyprusEurope2009-12-05 13:32:00
12373AustriaEurope2010-02-04 12:08:00
12374AustriaEurope2010-04-30 14:01:00
12384SwitzerlandEurope2011-08-10 11:23:00
customer_idnumber · unique id
12347
countrytext
Iceland
regiontext
Europe
first_order_atdate & time
2010-10-31 14:20:00
customer_idnumber · unique id
12353
countrytext
Bahrain
regiontext
Rest of World
first_order_atdate & time
2010-10-27 12:44:00
customer_idnumber · unique id
12359
countrytext
Cyprus
regiontext
Europe
first_order_atdate & time
2009-12-05 13:32:00
customer_idnumber · unique id
12373
countrytext
Austria
regiontext
Europe
first_order_atdate & time
2010-02-04 12:08:00
customer_idnumber · unique id
12374
countrytext
Austria
regiontext
Europe
first_order_atdate & time
2010-04-30 14:01:00
customer_idnumber · unique id
12384
countrytext
Switzerland
regiontext
Europe
first_order_atdate & time
2011-08-10 11:23:00

first 6 of 848 rows · your queries use all of them

worked example

Run these steps in order to see the idea before you write your own query. The step marked “the pattern” is what the challenges ask for. Running the example does not count toward progress.

  1. Count sales lines per month. Each row is one month’s line count on fact_sales—you see seasonality before you build any formal report.the pattern

    example.sql
    SELECT substr(order_date, 1, 7) AS month, COUNT(*) AS lines
    FROM fact_sales
    GROUP BY month;
  2. See the largest sale lines. The top ten rows by sales flag extreme quantities and amounts worth checking before you trust aggregates.

    step-2.sql
    SELECT sale_key, quantity, sales
    FROM fact_sales
    ORDER BY sales DESC
    LIMIT 10;

common mistake

COUNT(*) on fact_sales counts lines, not orders or customers; name each metric by what it counts.

challenge 1

Return one row from fact_sales with first_sale, last_sale, sales_lines and total_sales (rounded to 2 decimals).

what to return

Columns
first_salelast_salesales_linestotal_sales in this order
Rows
any order
challenge-1.sql
 
To master this lesson, solve both challenges without hints and pass the concept check. 3 of 3 to go.
EDA: explore before telling the story — Warehouse & reporting projects · Runtime