You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何按自然月汇总数据?bin_at函数无法适配月份天数差异

按自然月汇总Kusto数据的解决方案

不用bin_at固定30天间隔,Kusto提供了startofmonth()函数可以直接按自然月分组,完美适配不同月份的天数差异:

  • 核心思路:用startofmonth(TimeGenerated)将每条记录的时间戳转换为对应自然月的第一天,以此作为分组依据
  • 示例查询:
// 替换为你的表名
YourTable
| summarize TotalCount = count() 
// 按自然月第一天分组,自动适配1月31天、2月28/29天等情况
by MonthStart = startofmonth(TimeGenerated)

如果需要更易读的月份格式(如2022年01月),可以用format_datetime函数转换分组字段:

YourTable
| summarize TotalCount = count()
by Month = format_datetime(startofmonth(TimeGenerated), 'yyyy年MM月')

这个方法完全贴合自然月的时间边界,比固定天数的bin_at更精准。

内容的提问来源于stack exchange,提问作者Jerry

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 18:35:23