Is it possible to calculate some metrics (count, sum) for a specific time period like Today/This Week/This Month/Last Month in Cube.js. Is rollingWindow what I need? I tried it but it doesn't return me right data. Documentation is a bit confusing for me.
To be more descriptive I will use Orders table as an example.
I have simple Orders table in which I have product_id, product_name, created_at columns. On frontend i need to create analitycs table in which I will have product_name, this week (orders that are created this week for a specific product), this month (orders that are created this month for a specific product) and total orders by product.
Is there a way to do it like this:
measures: {
thisWeek: {
sql: 'id',
type: 'count',
filters: [{ sql: `${CUBE}.created_at = 'This week'` }],
},
}
In case someone has similar problem, I managed to do it like this:
In schema:
measures: {
thisWeek: {
sql: `id`,
type: `count`,
filters: [
{
sql: `${CUBE}.created_at >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 7 DAY)`,
},
],
},
thisMonth: {
sql: `id`,
type: `count`,
filters: [
{
sql: `${CUBE}.created_at >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 MONTH)`,
},
],
},
},
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.