简体   繁体   English

Cube.js 本周/本月

[英]Cube.js This Week/This Month

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.是否可以在 Cube.js 中计算特定时间段的某些指标(计数、总和),例如今天/本周/本月/上个月。 Is rollingWindow what I need? rollingWindow 是我需要的吗? 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.为了更具描述性,我将使用 Orders 表作为示例。

I have simple Orders table in which I have product_id, product_name, created_at columns.我有一个简单的订单表,其中有 product_id、product_name、created_at 列。 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.在前端,我需要创建 analitycs 表,其中我将包含产品名称、本周(本周为特定产品创建的订单)、本月(本月为特定产品创建的订单)和产品总订单。

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)`,
      },
    ],
  },
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM