Add column of totals pr. field value

半城伤御伤魂 提交于 2019-12-24 21:48:54

问题


I start with a list of failures that take place in locations

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

I can transform that into this table by using summarize count() by location

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

I'd like to transform the counts into percent on a per. failure basis, so I need to add a sum per failure name. My goal is to end up with this table:

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

Suggestions?


回答1:


Try this, to take you from your 2nd table to the 3rd (and extend a calculated column of the percentage):

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)



来源:https://stackoverflow.com/questions/53163317/add-column-of-totals-pr-field-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!