learning-it by example

Back to the video

Define a Metric Once: Views and a Metrics Layer

Two dashboards said 279 and 249 for one March; defined once, both said 150.

Video #130 ยท Data modelling

Steps in the video

  1. 0:00 Two dashboards, one March: 279 and 249. Defined once, both say 150.
  2. 0:29 The idea
  3. 1:06 Setup
  4. 1:24 The made-up orders
  5. 1:51 Two dashboards, two definitions
  6. 2:33 Define it once, as views
  7. 3:21 A tiny metric registry
  8. 3:47 Building the query
  9. 4:12 Two dashboards, one registry
  10. 4:51 What this does not show
  11. 5:22 Mistakes to avoid
  12. 5:52 My take and next steps
  13. 6:13 Recap

Files

  • dashboards.py (20 lines)
  • metrics.py (25 lines)
  • run.py (37 lines)
  • shop.py (21 lines)

Download the code (zip)

Tested with

Python 3.12.15

What this does not show

The orders are made up and the metrics layer is a small Python dict that builds SQL; no real semantic layer product, including dbt, is run.

Sources

Learning IT by Example.