Kusto 中 2 个连续值之间的差异

Difference between 2 consecutive values in Kusto

我有以下脚本:

let StartTime = datetime(2022-02-18 10:10:00 AM);
let EndTime = datetime(2022-02-18 10:15:00 AM);
MachineEvents
| where Timestamp between (StartTime .. EndTime)
| where Id == "00112233" and Name == "Higher"
| top 2 by Timestamp
| project Timestamp, Value

我得到以下结果:

之后我想要实现的是检查收到的最后一个值(在本例中为 15451.433)是否小于 30,000。如果条件为真,那么我应该再次检查最后两个连续值之间的差异(在本例中:15451.433 - 15457.083)。如果差异小于 0,那么我应该 return 值为真,否则它应该 return 为假(换句话说,值应该给出一个布尔值而不是双精度值,如图所示)

您可以使用 prev() 函数(或 next())来处理其他行中的值。

...
| extend previous = prev(value)
| extend diff = value - previous
| extend isPositive = diff > 0

如果您没有类似 top 的东西,您可能需要使用 serialize

datatable(Timestamp:datetime, Value:double)
[
 datetime(2022-02-18 10:15:00 AM), 15457.083,
 datetime(2022-02-18 10:14:00 AM), 15451.433,
 datetime(2022-02-18 10:13:00 AM), 15433.333,
 datetime(2022-02-18 10:12:00 AM), 15411.111
]
| top 2 by Timestamp
| project Timestamp, Value
| extend nextValue=next(Value)
| extend finalResult = iff(Value < 30000, nextValue - Value < 0, false)
| top 1 by Timestamp
| project finalResult

输出:

finalResult
1