Forum Discussion

WillAda's avatar
WillAda
Copper Contributor
Oct 26, 2021
Solved

Event that happened within 1-2 minutes of each other

I have just started to learn KQL and have started to experiment with some of the tables and trying to work out some simple dynamics of it.  One of the concepts I am trying to get my head around is lo...
  • Jonhed's avatar
    Oct 26, 2021

    WillAda

    You are merging the tables with the union operator, which only puts all the events in one bucket so to speak. To be able to filter with "where (End-Start)", both the End and Start attributes need to exist in the same event, so you need to use the join operator to join the myquery and myquery2 events together, instead of union.

     

     

     

    myquery | union myquery2
    | where (End-Start) between (0min .. 1min)

     

     

     

     

    In order to use join you will need a shared attribute that exists in both myquery and myquery2 though.

    Maybe something like below.

     

    I think it should work, though I am not sure if it is the ideal solution since I have not done anything like this myself. Also, since deviceID and deviceName etc exist in both tables, you will end up with duplicate attributes so should probably rename the attributes so they are not identical in myquery and myquery2. (for example rename DeviceID to DeviceID-1 in myquery, and DeviceID-2 in myquery2)

     

     

     

    .......
    let myquery1 = 
    ........
    | project ......, Start=Timestamp, Join="1"
    
    .......
    let myquery2 = 
    ........
    | project ......, End=Timestamp, Join="1"
    
    myquery | join kind=inner myquery2 on Join
    | where (End-Start) between (0min .. 1min)