{
'name': 'revenue_change',
'expression': "(lead(coalesce(sum(pl.revenue), 0)::integer, 1, 0) OVER (ORDER BY month_end DESC) - coalesce(sum(pl.revenue), 0)) AS delta"
}
"cubes": [
{
"name": "posts_to_social",
"label": "Posts to Social Media",
"dimensions": ["site", "social_provider", "posted_at"],
"aggregates": [
{
"name": "record_count",
"function": "count"
}
],
"mappings": {
"posted_at.year": {"column":"posted_at", "extract":"year"},
"posted_at.quarter": {"column":"posted_at", "extract":"quarter"},
"posted_at.month": {"column":"posted_at", "extract":"month"},
"posted_at.week": {"column":"posted_at", "extract":"week"},
"posted_at.day": {"column":"posted_at", "extract":"day"}
},
"joins": [
{"master":"site_id", "detail":"site.site_id"}
]
}
],
"dimensions": [
{ "name": "site", "attributes": ["site_id", "name"] },
{ "name": "social_provider" },
{ "name": "posted_at",
"label": "Posted",
"template": "date",
"order": "desc"
},
{
"comment": "This is used as a template for other date dimensions.",
"name": "date",
"label": "Date",
"role": "time",
"levels": [
{
"name": "year",
"order": "desc",
"order_attribute": "year",
"label": "Year"
},
{
"name": "quarter",
"label": "Quarter",
"order_attribute": "quarter",
"order": "desc"
},
{
"name": "month",
"label": "Month",
"order_attribute": "month",
"order": "desc"
},
{
"name": "week",
"label": "Week",
"order_attribute": "week",
"order": "desc"
},
{
"name": "day",
"label": "Day",
"order_attribute": "day",
"order": "desc"
}
],
"hierarchies": [
{
"name": "weekly",
"label": "Weekly",
"levels": ["year", "week"]
},
{
"name": "monthly",
"label": "Monthly",
"levels": ["year", "quarter", "month"]
},
{
"name": "daily",
"label": "Daily",
"levels": ["year", "month", "day"]
}
]
}
]
}
DEBUG SQL(aggregation drilldown):
SELECT EXTRACT(year FROM posts_to_social.posted_at) AS "posted_at.year", EXTRACT(quarter FROM posts_to_social.posted_at) AS "posted_at.quarter", EXTRACT(month FROM posts_to_social.posted_at) AS "posted_at.month", count(posts_to_social.id) AS record_count
FROM posts_to_social GROUP BY EXTRACT(year FROM posts_to_social.posted_at), EXTRACT(quarter FROM posts_to_social.posted_at), EXTRACT(month FROM posts_to_social.posted_at)
"GET /cube/posts_to_social/aggregate?drilldown=posted_at%40monthly%3Amonth HTTP/1.1"