使用 KQL(Kusto 查询语言),如何将日期时间分组为周(或 7 天的块)?
我正在针对 Azure Application Insights 运行 KQL(Kusto 查询语言)查询。我想每周汇总某些测量结果。我想弄清楚如何将我的数据分成几周。
为了说明我所寻求的内容,这里有一个计算duration列的每日平均值的查询。
requests
| where timestamp > ago(7d)
| summarize
avg(duration)
by
Date = format_datetime(timestamp, "yyyy-MM-dd")
这会产生类似的内容:
在上面,我已将日期时间转换为字符串,从而有效地将它们“四舍五入”到一天的精度。这可能很难看,但这是我能想到的对某一天的所有结果进行分组的最简单的方法。使用相同的技术将四舍五入到几个月或几年是微不足道的。
但是如果我想按周对日期时间进行分组怎么办?有什么好的方法可以做到这一点吗?
我不在乎我的“周”是从周一、周日、1 月 1 日还是其他什么开始。我只想将 KQL 日期时间集合分组为 7 天的块。我怎样才能做到这一点?
提前致谢!
I am running KQL (Kusto query language) queries against Azure Application Insights. I have certain measurements that I want to aggregate weekly. I am trying to figure out how to split my data into weeks.
To illustrate what I seek, here is a query that computes daily averages of the duration column.
requests
| where timestamp > ago(7d)
| summarize
avg(duration)
by
Date = format_datetime(timestamp, "yyyy-MM-dd")
This produces something similar to this:
In the above I have converted datetimes to string and thus effectively "rounded them down" to the precision of one day. This may be ugly, but it's the easiest way I could think of in order to group all results from a given day. It would be trivial to round down to months or years with the same technique.
But what if I want to group datetimes by week? Is there a nice way to do that?
I do not care whether my "weeks" start on Monday or Sunday or January 1st or whatever. I just want to group a collection of KQL datetimes into 7-day chunks. How can I do that?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您正在寻找“bin()”函数:
Looks like you are looking for the "bin()" function:
我发现我可以使用 week_of_year 函数按周数分割日期时间:
I found out that I can use the week_of_year function to split datetimes by week number: