添加总计栏栏位值

时间:2018-11-05 22:40:44

标签: kusto azure-data-explorer

我从位置发生的故障列表开始

failureName, failureLocation
failure a, location 1
failure b, location 1
failure a, location 2
failure a, location 1
<etc>

我可以通过按位置使用summarize count()来将其转换为该表

failureName, failureLocation, count
failure a, location 1, 100
failure a, location 2, 50
failure b, location 1, 10
<etc>

我想将计数转换为每个百分比。故障依据,因此我需要为每个故障名称添加一个总和。我的目标是创建此表:

failureName, failureLocation, count, sumPerFailureName
failure a, location 1, 100, 150
failure a, location 2, 50, 150
failure b, location 1, 10, 10
<etc>

建议?

1 个答案:

答案 0 :(得分:1)

尝试一下,将您从第二张表带到第三张表(并扩展百分比计算栏):

let T = datatable(failureName:string, failureLocation:string, ['count']:long) [ 'failure a', 'location 1', 100, 'failure a', 'location 2', 50, 'failure b', 'location 1', 10, ] ; T | summarize sumPerFailureName = sum(['count']) by failureName | join ( T ) on failureName | project failureName, failureLocation, ['count'], sumPerFailureName, percentage = round(100.0 * ['count'] / sumPerFailureName, 2)