{"views":[{"name":"active_customers","label":"Active customers","params":{"as_of":{"type":"date","default":{"sql":"SELECT max(order_date) FROM clean.orders"}},"region":{"type":"string","multi":true}},"query":"SELECT count(DISTINCT o.customer_id) AS active_customers\nFROM clean.orders o JOIN clean.customers c USING (customer_id)\nWHERE date_trunc('month', o.order_date) = date_trunc('month', $as_of)\n  AND ($region IS NULL OR list_contains($region, c.region))","panels":{"trend":"SELECT date_trunc('month', order_date)::DATE AS month, count(DISTINCT customer_id) AS customers\nFROM clean.orders WHERE order_date <= $as_of GROUP BY ALL ORDER BY month","by_region":"SELECT c.region, count(DISTINCT o.customer_id) AS customers\nFROM clean.orders o JOIN clean.customers c USING (customer_id)\nWHERE date_trunc('month', o.order_date) = date_trunc('month', $as_of)\nGROUP BY ALL ORDER BY customers DESC"},"display":{"unit":"customers"}},{"name":"revenue_by_region","label":"Net revenue by region","params":{"year":{"type":"int","default":{"sql":"SELECT max(year(order_date)) FROM clean.shop_orders_enriched"}},"region":{"type":"string","multi":true}},"query":"SELECT region, sum(amount) AS revenue FROM clean.shop_orders_enriched WHERE status = 'Completed'\n      AND year(order_date) = $year AND ($region IS NULL OR list_contains($region, region))\n      GROUP BY ALL ORDER BY revenue DESC","panels":{"by_month":"SELECT date_trunc('month', order_date)::DATE AS month, sum(amount) AS revenue FROM clean.shop_orders_enriched WHERE status = 'Completed'\n        AND year(order_date) = $year AND ($region IS NULL OR list_contains($region, region)) GROUP BY 1 ORDER BY 1","by_channel":"SELECT channel, sum(amount) AS revenue FROM clean.shop_orders_enriched WHERE status = 'Completed'\n        AND year(order_date) = $year AND ($region IS NULL OR list_contains($region, region))\n        GROUP BY ALL ORDER BY revenue DESC"},"display":{"unit":"USD"}},{"name":"sales_by_region","params":{},"query":"-- Ctrl/Cmd+Enter runs the statement under the cursor (or the selection).\n-- Type raw. (sources), clean. (prepared) or ref. (reference) for tables; hover a name for its type.\nSELECT *\nFROM raw.sales\nLIMIT 100","panels":{}},{"name":"top_products","label":"Top products in a month","params":{"month":{"type":"date","default":{"sql":"SELECT max(date_trunc('month', order_date))::DATE FROM clean.shop_orders_enriched"}}},"query":"SELECT product_name, sum(amount) AS revenue FROM clean.shop_orders_enriched WHERE status = 'Completed'\n      AND date_trunc('month', order_date) = $month GROUP BY ALL ORDER BY revenue DESC LIMIT 10","panels":{"by_category":"SELECT category, sum(amount) AS revenue FROM clean.shop_orders_enriched WHERE status = 'Completed'\n        AND date_trunc('month', order_date) = $month GROUP BY ALL ORDER BY revenue DESC"},"display":{"unit":"USD"}},{"name":"vendor_status","label":"Vendors by status","params":{"as_of":{"type":"date","default":{"sql":"SELECT max(_period) FROM raw.vendor_list"}}},"query":"SELECT status, count(*) AS vendors FROM raw.vendor_list WHERE _period = $as_of GROUP BY ALL ORDER BY vendors DESC","panels":{"by_country":"SELECT country, count(*) FILTER (status = 'Active') AS active_vendors FROM raw.vendor_list\n        WHERE _period = $as_of GROUP BY ALL ORDER BY active_vendors DESC","over_time":"SELECT _period AS month, count(*) FILTER (status = 'Active') AS active_vendors FROM raw.vendor_list\n        GROUP BY 1 ORDER BY 1"}}]}