cube(`custom_calendar`, {
calendar: true,
sql: `
SELECT '2025-01-01' AS date, '2024-12-15' AS month_ago UNION ALL
SELECT '2025-02-01' AS date, '2025-01-15' AS month_ago UNION ALL
SELECT '2025-03-01' AS date, '2025-02-15' AS month_ago UNION ALL
SELECT '2025-04-01' AS date, '2025-03-15' AS month_ago UNION ALL
SELECT '2025-05-01' AS date, '2025-04-15' AS month_ago UNION ALL
SELECT '2025-06-01' AS date, '2025-05-15' AS month_ago
`,
dimensions: {
date_key: {
sql: `${CUBE}.date::TIMESTAMP`,
type: `time`,
primary_key: true
},
date: {
sql: `${CUBE}.date::TIMESTAMP`,
type: `time`,
time_shift: [
{ type: `prior`, interval: `1 month`, sql: `${CUBE}.month_ago::TIMESTAMP` },
{ type: `prior`, interval: `42 days`, name: `my_favorite_time_shift` }
]
}
}
})
cube(`sales`, {
sql: `
SELECT 1 AS id, 101 AS amount, '2025-01-01'::TIMESTAMP AS date UNION ALL
SELECT 2 AS id, 202 AS amount, '2025-02-01'::TIMESTAMP AS date UNION ALL
SELECT 3 AS id, 303 AS amount, '2025-03-01'::TIMESTAMP AS date UNION ALL
SELECT 4 AS id, 404 AS amount, '2025-04-01'::TIMESTAMP AS date UNION ALL
SELECT 5 AS id, 505 AS amount, '2025-05-01'::TIMESTAMP AS date UNION ALL
SELECT 6 AS id, 606 AS amount, '2025-06-01'::TIMESTAMP AS date
`,
joins: {
custom_calendar: {
sql: `${CUBE}.date = ${custom_calendar.date_key}`,
relationship: `many_to_one`
}
},
dimensions: {
id: {
sql: `id`,
type: `number`,
primary_key: true
}
},
measures: {
total_sales: {
sql: `amount`,
type: `sum`
},
total_sales_prior_month: {
sql: `{total_sales}`,
type: `number`,
time_shift: [
{ type: `prior`, interval: `1 month` }
]
},
total_sales_few_days_ago: {
sql: `{total_sales}`,
type: `number`,
time_shift: [
{ name: `my_favorite_time_shift` }
]
}
}
})