agnes-the-ai-analyst/docs/metrics/revenue/revenue_by_channel.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

41 lines
1.2 KiB
YAML

- name: revenue_by_channel
display_name: Revenue by Channel
category: revenue
type: sum
unit: USD
grain: monthly
time_column: order_date
table: orders
expression: "SUM(total_amount) GROUP BY channel"
description: "Revenue breakdown by sales channel (web, mobile, in-store, marketplace). Identifies highest-performing channels and guides marketing spend allocation."
dimensions:
- channel
- region
- product_category
notes:
- "Channel is assigned at order creation and does not change"
- "Marketplace channel includes all third-party platforms (Amazon, eBay, etc.)"
- "Cross-channel attribution is not applied; each order is counted once"
synonyms:
- channel_revenue
- sales_by_channel
sql: |
SELECT
DATE_TRUNC('month', order_date) AS month,
channel,
SUM(total_amount) AS revenue,
COUNT(*) AS order_count
FROM orders
WHERE status = 'completed'
GROUP BY 1, 2
ORDER BY 1, 3 DESC
sql_by_region: |
SELECT
DATE_TRUNC('month', order_date) AS month,
channel,
region,
SUM(total_amount) AS revenue
FROM orders
WHERE status = 'completed'
GROUP BY 1, 2, 3
ORDER BY 1, 4 DESC