Quicksight中的avgOver

问题描述

我有2019年每个月的数据,但直到2020年9月。每行包含一个MonthNo.(对应于日历月)和一个用户ID条目。看起来像这样

| Month     | Year | ID     | MonthNo. |
|-----------|------|--------|----------|
| January   | 2019 | 611330 | 01       |
| January   | 2019 | 174519 | 01       |
| January   | 2019 | 380747 | 01       |
| February  | 2019 | 882347 | 02       |
| February  | 2019 | 633797 | 02       |
| February  | 2019 | 863219 | 02       |
| March     | 2019 | 189924 | 03       |
| March     | 2019 | 241922 | 03       |
| March     | 2019 | 563335 | 03       |
| April     | 2019 | 648660 | 04       |
| April     | 2019 | 363710 | 04       |
| April     | 2019 | 606284 | 04       |
| May       | 2019 | 296508 | 05       |
| May       | 2019 | 287650 | 05       |
| May       | 2019 | 599909 | 05       |
| June      | 2019 | 513844 | 06       |
| June      | 2019 | 891633 | 06       |
| June      | 2019 | 138250 | 06       |
| July      | 2019 | 126235 | 07       |
| July      | 2019 | 853840 | 07       |
| July      | 2019 | 713104 | 07       |
| August    | 2019 | 180511 | 08       |
| August    | 2019 | 451735 | 08       |
| August    | 2019 | 818095 | 08       |
| September | 2019 | 512621 | 09       |
| September | 2019 | 674079 | 09       |
| September | 2019 | 914015 | 09       |
| October   | 2019 | 132859 | 10       |
| October   | 2019 | 560572 | 10       |
| October   | 2019 | 272557 | 10       |
| November  | 2019 | 984001 | 11       |
| November  | 2019 | 815688 | 11       |
| November  | 2019 | 902748 | 11       |
| December  | 2019 | 880285 | 12       |
| December  | 2019 | 167629 | 12       |
| December  | 2019 | 772039 | 12       |
| January   | 2020 | 116886 | 01       |
| January   | 2020 | 386078 | 01       |
| February  | 2020 | 291060 | 02       |
| February  | 2020 | 970032 | 02       |
| March     | 2020 | 907555 | 03       |
| March     | 2020 | 560827 | 03       |
| April     | 2020 | 938039 | 04       |
| April     | 2020 | 721640 | 04       |
| May       | 2020 | 131719 | 05       |
| May       | 2020 | 415596 | 05       |
| June      | 2020 | 589375 | 06       |
| June      | 2020 | 623663 | 06       |
| July      | 2020 | 577748 | 07       |
| July      | 2020 | 999572 | 07       |
| August    | 2020 | 630975 | 08       |
| August    | 2020 | 442278 | 08       |
| September | 2020 | 993318 | 09       |
| September | 2020 | 413214 | 09       |

此示例表在2019年每个月正好有3条记录,在2020年每个月正好有2条记录。因此,当我添加由{p>定义的名为MonthNotYearTraffic的计算字段时

// Averages ID count by month number only,intentionally ignoring year.

avgOver(count(ID),[{MonthNo.}])

我希望得到以下结果

| MonthNo. | MonthNotYearTraffic |
|----------|---------------------|
| 01       | 2.5                 |
| 02       | 2.5                 |
| 03       | 2.5                 |
| 04       | 2.5                 |
| 05       | 2.5                 |
| 06       | 2.5                 |
| 07       | 2.5                 |
| 08       | 2.5                 |
| 09       | 2.5                 |
| 10       | 3                   |
| 11       | 3                   |
| 12       | 3                   |

因为10到12个月只有上述三个入围作品。但是结果是:

enter image description here

我已经尝试了以下几种不同的方式和组合(我知道其中几种是疯狂的,但其他人不确定):

  • 起初不依赖自定义的计算字段
  • 通过在计算出的字段定义中对月份和年份进行分区
  • 弄乱了级别感知的聚合
  • 通过确保要标记的数据类型为字符串/维度

没有骰子。

这似乎应该是简单易懂的技术,所以任何指针都很好。谢谢。

解决方法

似乎您需要按月划分ID的数量,然后将其除以该月拥有用户ID的年数。

使用示例数据,我可以获得所需的输出。

MonthNotYearTraffic = countover(ID,[Month],PRE_FILTER)/distinctCountOver(Year,PRE_FILTER)

enter image description here

,

我认为问题在于avgOver仅在显示数据的方式与在您定义问题中的值的第一个表中一样时才起作用。由于您仅显示MonthNo.字段,并且具有相同的MonthNo.值的行并不多,因此该分区中每个月只有一行,因此它只是将计数除以1。>

也许尝试类似count(ID) / count("MonthNo.")

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...