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
- 0:00 Two dashboards, one March: 279 and 249. Defined once, both say 150.
- 0:29 The idea
- 1:06 Setup
- 1:24 The made-up orders
- 1:51 Two dashboards, two definitions
- 2:33 Define it once, as views
- 3:21 A tiny metric registry
- 3:47 Building the query
- 4:12 Two dashboards, one registry
- 4:51 What this does not show
- 5:22 Mistakes to avoid
- 5:52 My take and next steps
- 6:13 Recap
Files
- dashboards.py (20 lines)
- metrics.py (25 lines)
- run.py (37 lines)
- shop.py (21 lines)
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.