以下两个选项都应该允许您计算您感兴趣的平均值:
(警告:这是基于您展示的示例,可能会被“简化”以不反映您的现实生活场景,因此请澄清以防万一这没有帮助):
let items = dynamic({"operation_Id": "12345Z12", "days":[43, 21, 65]});
print operationId = tostring(items.operation_Id), days = items.days
| mvexpand days to typeof(int)
| summarize avg(days) by operationId
// or
let items = dynamic({"operation_Id": "12345Z12", "days":[43, 21, 65]});
print operationId = tostring(items.operation_Id), days = items.days
| project operationId, series_stats_dynamic(days)['avg']
您的第二个示例确实无效(标量和表格参数不相等),但可以重写如下:
(与上述相同的警告)
let items = dynamic({"days":[43, 21, 65]});
let arraySum = (T:(x: long))
{
T
| summarize sum(x)
};
print items
| mvexpand x = items.days to typeof(long)
| invoke arraySum()
// or
let items = dynamic({"days":[43, 21, 65]});
print items
| project sum = series_stats_dynamic(items.days)["avg"] * array_length(items.days)
更新了后续提供的评论的示例:
datatable (Operation_id:string, customDimensions:dynamic)
[
"MTFfq", dynamic({"siteId": "1", "fileCount": "3", "pendingDays":[15,10,11]}),
"LXVjk", dynamic({"siteId": "2", "fileCount": "1", "pendingDays":[3]}),
"jnySt", dynamic({"siteId": "3", "fileCount": "2", "pendingDays":[7,11]}),
"NoxoX", dynamic({"siteId": "4", "fileCount": "4", "pendingDays":[1,4,3,11]})
]
| mvexpand days = customDimensions.pendingDays to typeof(int)
| summarize avg(days) by Operation_id
// or
datatable (Operation_id:string, customDimensions:dynamic)
[
"MTFfq", dynamic({"siteId": "1", "fileCount": "3", "pendingDays":[15,10,11]}),
"LXVjk", dynamic({"siteId": "2", "fileCount": "1", "pendingDays":[3]}),
"jnySt", dynamic({"siteId": "3", "fileCount": "2", "pendingDays":[7,11]}),
"NoxoX", dynamic({"siteId": "4", "fileCount": "4", "pendingDays":[1,4,3,11]})
]
| project Operation_id, series_stats_dynamic(customDimensions.pendingDays)['avg']
和:
let arraySum = (T:(x: long))
{
T
| summarize sum(x)
};
datatable (Operation_id:string, customDimensions:dynamic)
[
"MTFfq", dynamic({"siteId": "1", "fileCount": "3", "pendingDays":[15,10,11]}),
"LXVjk", dynamic({"siteId": "2", "fileCount": "1", "pendingDays":[3]}),
"jnySt", dynamic({"siteId": "3", "fileCount": "2", "pendingDays":[7,11]}),
"NoxoX", dynamic({"siteId": "4", "fileCount": "4", "pendingDays":[1,4,3,11]})
]
| mvexpand x = customDimensions.pendingDays to typeof(long)
| invoke arraySum()
// or
datatable (Operation_id:string, customDimensions:dynamic)
[
"MTFfq", dynamic({"siteId": "1", "fileCount": "3", "pendingDays":[15,10,11]}),
"LXVjk", dynamic({"siteId": "2", "fileCount": "1", "pendingDays":[3]}),
"jnySt", dynamic({"siteId": "3", "fileCount": "2", "pendingDays":[7,11]}),
"NoxoX", dynamic({"siteId": "4", "fileCount": "4", "pendingDays":[1,4,3,11]})
]
| project Operation_id, sum = series_stats_dynamic(customDimensions.pendingDays)["avg"] * array_length(customDimensions.pendingDays)
上面使用的运算符/函数的一些参考: