Cube.js 本周/本月

问题描述 投票:0回答:2

是否可以在 Cube.js 中计算特定时间段的某些指标(计数、总和),例如今天/本周/本月/上个月。滚动窗口是我需要的吗?我尝试过,但它没有返回正确的数据。文档对我来说有点混乱。

为了更具描述性,我将使用 Orders 表作为示例。

我有一个简单的订单表,其中有product_id、product_name、created_at 列。在前端,我需要创建 analitycs 表,其中包含产品名称、本周(本周为特定产品创建的订单)、本月(本月为特定产品创建的订单)以及按产品列出的总订单。

有没有办法这样做:

measures: {
    thisWeek: {
      sql: 'id',
      type: 'count',
      filters: [{ sql: `${CUBE}.created_at = 'This week'` }],
    },
}
javascript sql vue.js sequelize.js cube.js
2个回答
0
投票

如果有人有类似的问题,我设法这样做:

在架构中:

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

0
投票

您对rolling_window 尝试了哪些配置但不起作用?以下内容应该有效,并且应该为您提供与您在答案中发布的相同的值。但是,您需要使用“created_at”作为您的时间维度。

dimensions: {
    collector_date: {
      sql: `TIMESTAMP(created_at)`,
      type: `time`
    },
},
measures: {
  thisWeek: {
    sql: `id`,
    type: `count`,
    rolling_window: {
        offset: `end`,
        trailing: `7 day`,
    },
  },
  thisMonth: {
    sql: `id`,
    type: `count`,
    rolling_window: {
        offset: `end`,
        trailing: `1 month`,
    },
  },
},

请告诉我这是否有效!

© www.soinside.com 2019 - 2024. All rights reserved.