Search code examples
kqlazure-data-explorer

KQL split row into several row with numeric resolution


I want to split a row like

Row Event StartIndex EndIndex
1 A 0 3
2 B 1.9 2.7

That in the new table, the Event will be written several times with specific index based on StartIndex and EndIndex, with a resolution of 0.5. For example, the expected output is:

Row Event Index
1 A 0
2 A 0.5
3 A 1
4 A 1.5
5 A 2
6 A 2.5
7 A 3
8 B 2
9 B 2.5

How can I do that in KQL?


Solution

  • this should get you started - using range() and mv-expand. if required, you can extend the solution and 'override' Row using the row_number() function.

    datatable(Row:long, Event:string, StartIndex:long, EndIndex:long)
    [
        1, 'A', 0,  3,
        2, 'B', 1.9,    2.7,
    ]
    | mv-expand Index = range(StartIndex, EndIndex, 0.5)
    | project Row, Event, Index
    
    Row Event Index
    1 A 0
    1 A 0.5
    1 A 1
    1 A 1.5
    1 A 2
    1 A 2.5
    1 A 3
    2 B 2
    2 B 2.5
    2 B 3