agnes-the-ai-analyst/docs/metrics/revenue/total_revenue.yml
Petr 5a84473213 Add dynamic Business Metrics with sample e-commerce definitions
Replace hardcoded Keboola-specific metrics card in Data Catalog with
dynamic Jinja template that renders whatever metric YAMLs exist in
docs/metrics/. Add 10 sample e-commerce metric definitions across
4 categories (revenue, customers, marketing, support) that align
with the sample data generator tables.

Key changes:
- MetricParser: new category colors + dynamic sql_* field discovery
- _load_metrics_data(): scans docs/metrics/*/*.yml with prod fallback
- catalog.html: 240 lines hardcoded HTML -> 35 lines Jinja loop
- metric_modal.js: regex-based category class removal, new categories
- 21 tests validating YAML schema, parser, and loader
2026-03-10 22:38:44 +01:00

40 lines
1.1 KiB
YAML

- name: total_revenue
display_name: Total Revenue
category: revenue
type: sum
unit: USD
grain: monthly
time_column: order_date
table: orders
expression: "SUM(total_amount)"
description: "Total revenue from all orders. Primary top-line metric tracking overall business performance across all channels and product categories."
dimensions:
- channel
- product_category
- region
- payment_method
notes:
- "Includes all completed orders, excludes cancelled and refunded"
- "Revenue is recognized at order completion date, not payment date"
- "Multi-currency orders are converted to USD at daily exchange rate"
synonyms:
- gross_revenue
- total_sales
- top_line_revenue
sql: |
SELECT
DATE_TRUNC('month', order_date) AS month,
SUM(total_amount) AS total_revenue
FROM orders
WHERE status = 'completed'
GROUP BY 1
ORDER BY 1
sql_by_channel: |
SELECT
DATE_TRUNC('month', order_date) AS month,
channel,
SUM(total_amount) AS revenue
FROM orders
WHERE status = 'completed'
GROUP BY 1, 2
ORDER BY 1, 3 DESC