如果我正确理解要求,您可以对数据集进行排序,然后使用case()
andprev()
函数。
例如:
datatable(customer:string, PipelineType:string, PipelineState:string, TimeStamp:datetime)
[
'CustomerA', 'Pipeline A', 'Fail', datetime(2021-08-13 12:59:03.0073653),
'CustomerA', 'Pipeline A', 'Fail', datetime(2021-08-13 09:59:03.0124853),
'CustomerA', 'Pipeline B', 'Success', datetime(2021-08-13 11:56:03.0151948),
'CustomerA', 'Pipeline B', 'Fail', datetime(2021-08-12 17:56:03.0019445),
'CustomerA', 'Pipeline C', 'Success', datetime(2021-08-13 13:16:03.0015617),
'CustomerA', 'Pipeline C', 'Fail', datetime(2021-07-30 21:52:03.0157372),
'CustomerB', 'Pipeline A', 'Fail', datetime(2021-08-13 12:59:03.0073331),
'CustomerB', 'Pipeline A', 'Success', datetime(2021-08-13 12:57:03.0099138),
'CustomerB', 'Pipeline B', 'Fail', datetime(2021-07-30 03:33:03.0123262),
'CustomerB', 'Pipeline B', 'Success', datetime(2021-08-13 13:16:03.0015297),
'CustomerB', 'Pipeline C', 'Fail', datetime(2021-08-13 12:57:03.0099499),
'CustomerB', 'Pipeline C', 'Success', datetime(2021-08-13 13:16:03.0016348),
'CustomerC', 'Pipeline A', 'Fail', datetime(2021-08-13 13:16:03.0016999),
'CustomerC', 'Pipeline A', 'Fail', datetime(2021-08-13 12:59:03.0074113),
'CustomerC', 'Pipeline B', 'Success', datetime(2021-08-13 10:56:03.0075546),
'CustomerC', 'Pipeline B', 'Fail', datetime(2021-08-11 06:54:03.0118628),
'CustomerC', 'Pipeline C', 'Fail', datetime(2021-08-13 13:16:03.0016233),
'CustomerC', 'Pipeline C', 'Fail', datetime(2021-08-13 12:59:03.0072337),
]
| order by customer asc, PipelineType asc, TimeStamp asc
| extend result = case(prev(customer) == customer and prev(PipelineType) == PipelineType and PipelineState == 'Fail', TimeStamp - prev(TimeStamp), timespan(null))
顾客 |
管道类型 |
管道状态 |
时间戳 |
结果 |
客户A |
管道 A |
失败 |
2021-08-13 09:59:03.0124853 |
|
客户A |
管道 A |
失败 |
2021-08-13 12:59:03.0073653 |
02:59:59.9948800 |
客户A |
管道 B |
失败 |
2021-08-12 17:56:03.0019445 |
|
客户A |
管道 B |
成功 |
2021-08-13 11:56:03.0151948 |
|
客户A |
管道 C |
失败 |
2021-07-30 21:52:03.0157372 |
|
客户A |
管道 C |
成功 |
2021-08-13 13:16:03.0015617 |
|
客户B |
管道 A |
成功 |
2021-08-13 12:57:03.0099138 |
|
客户B |
管道 A |
失败 |
2021-08-13 12:59:03.0073331 |
00:01:59.9974193 |
客户B |
管道 B |
失败 |
2021-07-30 03:33:03.0123262 |
|
客户B |
管道 B |
成功 |
2021-08-13 13:16:03.0015297 |
|
客户B |
管道 C |
失败 |
2021-08-13 12:57:03.0099499 |
|
客户B |
管道 C |
成功 |
2021-08-13 13:16:03.0016348 |
|
客户C |
管道 A |
失败 |
2021-08-13 12:59:03.0074113 |
|
客户C |
管道 A |
失败 |
2021-08-13 13:16:03.0016999 |
00:16:59.9942886 |
客户C |
管道 B |
失败 |
2021-08-11 06:54:03.0118628 |
|
客户C |
管道 B |
成功 |
2021-08-13 10:56:03.0075546 |
|
客户C |
管道 C |
失败 |
2021-08-13 12:59:03.0072337 |
|
客户C |
管道 C |
失败 |
2021-08-13 13:16:03.0016233 |
00:16:59.9943896 |
更新:回复您的评论 - 只需添加适当的过滤器。
例如:
datatable(customer:string, PipelineType:string, PipelineState:string, TimeStamp:datetime)
[
'CustomerA', 'Pipeline A', 'Fail', datetime(2021-08-13 12:59:03.0073653),
'CustomerA', 'Pipeline A', 'Fail', datetime(2021-08-13 09:59:03.0124853),
'CustomerA', 'Pipeline B', 'Success', datetime(2021-08-13 11:56:03.0151948),
'CustomerA', 'Pipeline B', 'Fail', datetime(2021-08-12 17:56:03.0019445),
'CustomerA', 'Pipeline C', 'Success', datetime(2021-08-13 13:16:03.0015617),
'CustomerA', 'Pipeline C', 'Fail', datetime(2021-07-30 21:52:03.0157372),
'CustomerB', 'Pipeline A', 'Fail', datetime(2021-08-13 12:59:03.0073331),
'CustomerB', 'Pipeline A', 'Success', datetime(2021-08-13 12:57:03.0099138),
'CustomerB', 'Pipeline B', 'Fail', datetime(2021-07-30 03:33:03.0123262),
'CustomerB', 'Pipeline B', 'Success', datetime(2021-08-13 13:16:03.0015297),
'CustomerB', 'Pipeline C', 'Fail', datetime(2021-08-13 12:57:03.0099499),
'CustomerB', 'Pipeline C', 'Success', datetime(2021-08-13 13:16:03.0016348),
'CustomerC', 'Pipeline A', 'Fail', datetime(2021-08-13 13:16:03.0016999),
'CustomerC', 'Pipeline A', 'Fail', datetime(2021-08-13 12:59:03.0074113),
'CustomerC', 'Pipeline B', 'Success', datetime(2021-08-13 10:56:03.0075546),
'CustomerC', 'Pipeline B', 'Fail', datetime(2021-08-11 06:54:03.0118628),
'CustomerC', 'Pipeline C', 'Fail', datetime(2021-08-13 13:16:03.0016233),
'CustomerC', 'Pipeline C', 'Fail', datetime(2021-08-13 12:59:03.0072337),
]
| order by customer asc, PipelineType asc, TimeStamp asc
| where not((prev(customer) == customer and prev(PipelineType) == PipelineType and PipelineState == 'Success' and prev(PipelineState) == 'Fail') or
(prev(customer) == customer and prev(PipelineType) == PipelineType and PipelineState == 'Fail' and next(PipelineState) == 'Success'))
| extend result = case(prev(customer) == customer and prev(PipelineType) == PipelineType and PipelineState == 'Fail', TimeStamp - prev(TimeStamp), timespan(null))
顾客 |
管道类型 |
管道状态 |
时间戳 |
结果 |
客户A |
管道 A |
失败 |
2021-08-13 09:59:03.0124853 |
|
客户A |
管道 A |
失败 |
2021-08-13 12:59:03.0073653 |
02:59:59.9948800 |
客户A |
管道 B |
失败 |
2021-08-12 17:56:03.0019445 |
|
客户A |
管道 C |
失败 |
2021-07-30 21:52:03.0157372 |
|
客户B |
管道 A |
成功 |
2021-08-13 12:57:03.0099138 |
|
客户B |
管道 A |
失败 |
2021-08-13 12:59:03.0073331 |
00:01:59.9974193 |
客户B |
管道 B |
失败 |
2021-07-30 03:33:03.0123262 |
|
客户B |
管道 C |
失败 |
2021-08-13 12:57:03.0099499 |
|
客户C |
管道 A |
失败 |
2021-08-13 12:59:03.0074113 |
|
客户C |
管道 A |
失败 |
2021-08-13 13:16:03.0016999 |
00:16:59.9942886 |
客户C |
管道 B |
失败 |
2021-08-11 06:54:03.0118628 |
|
客户C |
管道 C |
失败 |
2021-08-13 12:59:03.0072337 |
|
客户C |
管道 C |
失败 |
2021-08-13 13:16:03.0016233 |
00:16:59.9943896 |