使用顶级嵌套 Kusto 运算符时保存订单

Save order when using top-nested Kusto operator

我正在尝试通过使用顶部嵌套的 Kusto 运算符导出到 xlsx 来生成分层聚合并且效果很好,但我正在丢失我的默认顺序“Class”和“日期”字段使用查询:

Test | top-nested 25 of Class by sum(Value),  top-nested 25 of Date by sum(Value)

我在数据库中的数据xlsx file

这张图片的预期结果(同上,但按 Class 排序) 查询:

Test | where (tolower(Class) == tolower('Väganläggning'))| summarize sum(Value) by Date | take 25

但是我得到的数据的“日期”和“Class”的顺序很奇怪,就像这个导出的 xlsx 文件(第一个“日期”是 2029 年2009 等)

看来我需要这样的查询

Test | where Class == prev(Class) | top-nested 25 of Class by sum(Value), top-nested 25 of Date by sum(Value)

但我对 Kusto 没有经验,所以需要帮助的人)

最后一个维度列转到 Excel 数据透视表中的 Values 部分。
其余列转到 Rows 部分。

// Generate data sample. Not part of the solution.
let Test = materialize
(
    range i from 1 to 1000000 step 1 
    | extend Class = strcat("Class-", tostring(toint(rand(10))))
            ,Date  = startofday(ago(1d*rand(30)))
            ,Value = rand()
            ,Dim1  = strcat("Dim1-", tostring(toint(rand(10))))
            ,Dim2  = strcat("Dim2-", tostring(toint(rand(10))))
            ,Dim3  = strcat("Dim3-", tostring(toint(rand(10))))
);
// Solution starts here.
Test
| top-nested 4 of Class by sum(Value)
 ,top-nested 3 of Date  by sum(Value)
 ,top-nested 2 of Dim1  by sum(Value)
 ,top-nested 2 of Dim2  by sum(Value)
 ,top-nested 2 of Dim3  by sum(Value) 
| order by aggregated_Class ,Class asc
          ,aggregated_Date  ,Date  asc
          ,aggregated_Dim1  ,Dim1 asc
          ,aggregated_Dim2  ,Dim2 asc
          ,aggregated_Dim3  ,Dim3 asc
| project-rename Values = aggregated_Dim3
| project-away aggregated_*
Class Date Dim1 Dim2 Dim3 Values
Class-1 2022-05-10T00:00:00Z Dim1-2 Dim2-8 Dim3-8 5.1418120760105817
Class-1 2022-05-10T00:00:00Z Dim1-2 Dim2-8 Dim3-4 4.8139672995169027
Class-1 2022-05-10T00:00:00Z Dim1-2 Dim2-5 Dim3-4 3.6333999871855704
Class-1 2022-05-10T00:00:00Z Dim1-2 Dim2-5 Dim3-0 3.5165481405530339
Class-1 2022-05-10T00:00:00Z Dim1-6 Dim2-9 Dim3-3 3.526092609498761

(仅输出样本)

Fiddle