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 id | order_idnumber | customer_keynumber · links to dim_customer | product_keynumber · links to dim_product | order_datedate | quantitynumber | salesdecimal |
|---|---|---|---|---|---|---|
| 65625 | 3679 | 556 | 2062 | 2011-01-04 | 8 | 34 |
| 65626 | 3679 | 556 | 881 | 2011-01-04 | 1 | 7.95 |
| 65627 | 3679 | 556 | 887 | 2011-01-04 | 1 | 4.95 |
| 65628 | 3679 | 556 | 401 | 2011-01-04 | 2 | 5.9 |
| 65629 | 3679 | 556 | 4059 | 2011-01-04 | 36 | 30.6 |
| 65630 | 3679 | 556 | 4301 | 2011-01-04 | 10 | 29.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 id | countrytext | regiontext | first_order_atdate & time |
|---|---|---|---|
| 12347 | Iceland | Europe | 2010-10-31 14:20:00 |
| 12353 | Bahrain | Rest of World | 2010-10-27 12:44:00 |
| 12359 | Cyprus | Europe | 2009-12-05 13:32:00 |
| 12373 | Austria | Europe | 2010-02-04 12:08:00 |
| 12374 | Austria | Europe | 2010-04-30 14:01:00 |
| 12384 | Switzerland | Europe | 2011-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.
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.sqlSELECT substr(order_date, 1, 7) AS month, COUNT(*) AS lines FROM fact_sales GROUP BY month;
See the largest sale lines. The top ten rows by sales flag extreme quantities and amounts worth checking before you trust aggregates.
step-2.sqlSELECT 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.