let month = 12;
let year = 2024;
let base =
range day from startofday(now() - 1000d) to startofday(now()) step 1d
| where datetime_part("Month", day) == month and datetime_part("Year", day) == year
| project Week_Of_Year = datetime_part("Week_Of_Year", day), Month_Of_Year = datetime_part("Month", day)
| distinct Week_Of_Year, Month_Of_Year
| project Week_Of_Year, Month_Of_Year;
let max_week =
base
| summarize Max_Week = max(Week_Of_Year);
max_week
| extend Adjusted_Week = iif(Week_Of_Year == 1 and Month == 12, Max_Week + 1, Week_Of_Year)
尝试此操作但出现错误 EM0100:“扩展”运算符:无法解析名为“Week_Of_Year”的列或标量表达式” 如果是 1 或 12,我想要一年中的三周或三月,所以它会在一周的最大值上加 1。
如果月份=12,年份=2024,那么我想要每周最多48,49,50,51,52,53,即52 +1,所以53应该在那里
您可以使用下面的 KQL 查询来执行此操作:
let ri_mnth = 12;
let ri_yr = 2024;
let rith_table =
range day from startofday(now() - 1000d) to startofday(now()) step 1d
| where datetime_part("Month", day) == ri_mnth and datetime_part("Year", day) == ri_yr
| project Week_Of_Year = datetime_part("Week_Of_Year", day), Month_Of_Year = datetime_part("Month", day)
| distinct Week_Of_Year, Month_Of_Year;
let ri_max_wk =
rith_table
| summarize Max_Week = max(Week_Of_Year);
rith_table
| extend Max_Week = toscalar(ri_max_wk)
| extend Rith_Adjusted_wk = iif(Week_Of_Year == 1 and Month_Of_Year == ri_mnth, Max_Week + 1, Week_Of_Year)
| project Week_Of_Year, Rith_Adjusted_wk
输出: