source: orders is table('sales.orders') {
primary_key: order_id
join_one: customers is table('sales.customers') on customer_id
join_one: products is table('catalog.products') on product_id
dimension:
#(doc) Date the order was placed
order_date is created_at::date
#(doc) Order status: pending, processing, shipped, delivered, cancelled
#(index_values) n=-1
status is order_status
#(doc) Product category from the catalog
#(index_values) n=50
category is products.category
#(doc) Customer's geographic region
#(index_values) n=20
region is customers.region
measure:
#(doc) Total number of orders
order_count is count()
#(doc) Total revenue in USD
total_revenue is sum(amount)
#(doc) Average revenue per order in USD
avg_order_value is total_revenue / order_count
#(doc) Percentage of orders that were cancelled
cancellation_rate is count() { where: status = 'cancelled' } / order_count * 100
view:
#(doc) Monthly revenue trend with order counts
monthly_revenue is {
group_by: order_date.month
aggregate: total_revenue, order_count
}
}