How can I use for loop in kusto query.

Manoj Bobade 26 Reputation points
2021-08-31T11:25:53.963+00:00

I what get time difference between each row timestamp please check attached screen shot

EX: I want process all row one by one in for loop, suppose table contain 5 record
1st record timestamp 8/18/2021, 12:21:33.438 PM
2st record timestamp 8/18/2021, 12:22:34.438 PM
3st record timestamp 8/18/2021, 13:21:33.438 PM
4st record timestamp 8/18/2021, 13:21:34.438 PM
5st record timestamp 8/18/2021, 13:21:35.438 PM

here I want to get time difference between 2nd and 3rd record.

PLEASE DO NEEDFUL.

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
2,783 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Stanislav Zhelyazkov 20,616 Reputation points MVP
    2021-08-31T12:04:50.533+00:00

    Hi,
    There is no particular function for loop. I would guess the thing that you want to achieve is something like:

    Perf  
    | where ObjectName == "LogicalDisk"  
    | where CounterName == "Disk Read Bytes/sec"  
    | where InstanceName == "C:"  
    | where _ResourceId == "/subscriptions/ebb79bc0-aa86-44a7-8111-cabbe0c43993/resourcegroups/ch1-fabrikamrg/providers/microsoft.compute/virtualmachines/ch1-retailvm01"  
    | serialize   
    | extend someValue = prev(TimeGenerated, 1) - TimeGenerated  
    

    You can check the query against the public Log Analytics demo env.

    result looks like this
    127886-image.png

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    0 comments No comments