kql - Compare multiple column value and return column name with max value - Stack Overflow

I need to compare value in multiple column (up to 10) and to return the column name where there is the

I need to compare value in multiple column (up to 10) and to return the column name where there is the max value (for each row).

I did some try with array_sort_asc() but I'm not able to create a proper array with column "value".

Example :

Application 1 Application 2 Application 3
3 20 1

I need to compare value in multiple column (up to 10) and to return the column name where there is the max value (for each row).

I did some try with array_sort_asc() but I'm not able to create a proper array with column "value".

Example :

Application 1 Application 2 Application 3
3 20 1

I need to get "Application 2" as output

Any idea ? :) thanks

Share Improve this question asked Jan 31 at 9:49 PierrotPierrot 191 silver badge4 bronze badges 2
  • Could you please share what you tried? – Balaji Commented Jan 31 at 10:10
  • @Balaji I stuck to create a dynamic with column value. | extend array = dynamic (Application1, Application2, Application3) it's not accepted – Pierrot Commented Jan 31 at 10:15
Add a comment  | 

1 Answer 1

Reset to default 0

Try with the below code, it uses pack() function to create dynamic JSON object. It uses bag_keys(Apps) to extracts the keys (Application 1, Application 2, Application 3) as an array and mv-expand splits the keys into separate rows. Now convert AppKey to a string and extract the corresponding value from the Apps. Use arg_max(AppValue, AppKey) to find the application with the highest value in each row.

let data = datatable(Application_1:int, Application_2:int, Application_3:int)
[
    3, 20, 1,
    15, 8, 22,
    5, 25, 10
];

data
| extend Apps = pack('Application 1', Application_1, 'Application 2', Application_2, 'Application 3', Application_3) 
| mv-expand AppKey = bag_keys(Apps)
| extend AppKey = tostring(AppKey)  
| extend AppValue = toint(Apps[AppKey])  
| summarize MaxApplication = arg_max(AppValue, AppKey) by Application_1, Application_2, Application_3
| project Application_1, Application_2, Application_3, MaxApplication=AppKey

Output:

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745270821a4619734.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信