Metrics Store in Action

Paul Kinsvater23 Feb 2023

Problem

Teams that compute the same KPI in their own tools end up with different numbers. The logic sits in SQL procedures behind restricted access, in local Power BI files and in notebooks, so nobody can say how a figure was calculated. Teams argue over which revenue figure is right, and a figure sent to an audit can disagree with the dashboard.

Example from the article: sales assigns a revenue record to a quarter by "date closed", finance by "date booked". Revenue records tied to cancellations are removed under rules that differ between business units, and transactions in several currencies have no agreed exchange rate for each date.

Solution in brief

Keep the transformation layer for cleaning and row-level preparation. Define every metric and its dimensions once, in YAML kept in a git repository, in a metrics store. BI tools, reports and notebooks request KPIs through the store's API, and the store generates the SQL. If two teams need different versions of a KPI, define both.

Questions this case answers
  • How to keep one governed definition of each business metric when several teams and tools compute it independently from the same warehouse tables
  • How to make the same KPI show the same number in the dashboard, the analyst's notebook and the report?
  • How to decide which calculations belong in the transformation layer and which in the metrics layer?
  • How to let BI tools and notebooks request metrics without re-implementing their SQL?

Tools and methods

  • Metrics store (semantic layer) — central definitions of metrics and dimensions that turn requests into SQL
  • MetricFlow — open-source Python metrics store with CLI and Python APIs
  • dbt — transformation layer: staging models as views, final "marts" as tables
  • DuckDB — local warehouse for the tutorial
  • Streamlit — app that requests metrics from MetricFlow through Python
Continue reading — it's free

Google or a one-time email code. No password.