ericOnline
ericOnline

Reputation: 1967

Kusto Custom Sort Order?

How do I perform a custom sort order in Kusto?

Example query:

//==================================================//
// Assign variables
//==================================================//
let varStart = ago(2d);
let varEnd = now();
let varStorageAccount = 'stgacctname';
//==================================================//
// Filter table
//==================================================//
StorageBlobLogs
| where TimeGenerated between (varStart .. varEnd)
  and AccountName == varStorageAccount
| sort by OperationName

Need:

Is this possible?

Upvotes: 7

Views: 4054

Answers (1)

Slavik N
Slavik N

Reputation: 5298

Use an aux column, like this:

datatable(OperationName:string, SomethingElse:string)
[
    "AppendFile", "3",
    "GetBlob", "1",
    "AppendFile", "4",
    "GetBlob", "2"
]
| extend OrderPriority =
    case(OperationName == "GetBlob", 1,
         OperationName == "AppendFile", 2,
         3)
| order by OrderPriority asc, SomethingElse asc 
| project-away OrderPriority

Output:

OperationName SomethingElse
GetBlob 1
GetBlob 2
AppendFile 3
AppendFile 4

Upvotes: 8

Related Questions