【问题标题】:Aggregate data per Bank and per day in KQL以 KQL 形式汇总每个银行和每天的数据
【发布时间】:2021-04-29 02:50:38
【问题描述】:

我正在开展项目,目标是将荷兰的多家银行连接到我们的平台。

目前,每次用户连接到一家银行时,我们都希望发送一个指标并将其显示在 Azure 仪表板中。 我们快到了,除了我们想汇总每天的总和。这就是我们现在所拥有的:

例如,看看荷兰银行,我们有:

  1. ABN AMRO 在 25/01/2021 有 2081 个连接
  2. ABN AMRO 在 2021 年 1 月 24 日有 2325 个连接
  3. ABN AMRO 在 23/31/2021 有 5082 个连接

但我们想要的是这样总结:

  1. ABN AMRO 在 25/01/2021 有 2081 + 2325 + 5082 = 9488
  2. ABN AMRO 在 2021 年 1 月 24 日有 2325 + 5082 = 7407
  3. ABN AMRO 在 2021 年 23 月 31 日有 5082 = 5082

这是目前使用的查询:

customMetrics
| where name == "CustomerGrantedConsent"
| extend BankName = customDimensions.BankName
| summarize Count = count() by tostring(BankName), bin(timestamp, 1d)
| order by timestamp

怎么做?

【问题讨论】:

  • 这不行吗?只需在最后两行之间添加| summarize sum(CC) as total_by_bank_time by TT, BB| summarize CC = count() by tostring(BankName) as BB, bin(timestamp, 1d) as TT| order by timestamp

标签: azure azure-devops azure-functions kql


【解决方案1】:

尝试使用row_cumsum

customMetrics
| where name == "CustomerGrantedConsent"
| extend BankName = customDimensions.BankName
| summarize Count = count() by tostring(BankName), bin(timestamp, 1d)
| order by timestamp
| serialize
| extend cumsum = row_cumsum(Count, BankName != prev(BankName))

它将根据您的要求返回输出

  1. ABN AMRO 在 2021 年 1 月 25 日有 2081 + 2325 + 5082 = 9488
  2. ABN AMRO 在 2021 年 1 月 24 日有 2325 + 5082 = 7407
  3. ABN AMRO 在 23/31/2021 有 5082 = 5082

您可以在 here 阅读有关 row_cusmum 的信息。

【讨论】:

  • 这个可行,但我想要银行的 cusmun
【解决方案2】:
let T = datatable(day:datetime  , value:long)
[
   "2021-01-25", 3000,
   "2021-01-24", 2000,
   "2021-01-23", 1000
];
T
| order by day asc 
| serialize cs=row_cumsum(value)
| project  day, cs

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-24
  • 2021-09-07
  • 2022-07-07
  • 1970-01-01
  • 1970-01-01
  • 2016-08-27
相关资源
最近更新 更多