在KQL中投射一周中的每一天

问题描述

我要在Azure仪表板中创建一个磁贴,该磁贴显示过去7天的异常,但是,下面的KQL显然只会返回特定日期发生异常的数据点。

如何在没有例外的一天将其返回零?

exceptions
| where (* has 'insights')
    and timestamp >= ago(7d)
| summarize Count=count() 
     by Date2=bin(timestamp,1d)
| project Date=(format_datetime(Date2,'dd-MM-yyyy')),Count
| sort by Date

解决方法

使用make_series而不是摘要。

这是一个例子:

range x from 0 to 99 step 1
| where x !between(60 .. 79)
| make-series count() on x step 10
| mv-expand count_,x
| project x,count_

输出:

| x  | count_ |
|----|--------|
| 0  | 10     |
| 10 | 10     |
| 20 | 10     |
| 30 | 10     |
| 40 | 10     |
| 50 | 10     |
| 60 | 0      |
| 70 | 0      | 
| 80 | 10     |
| 90 | 10     |