Share via

Join/loop through KQL query result

RT-7199 516 Reputation points
2023-01-16T21:36:51.87+00:00

Below gives me a table of distinct usernames

WVDConnections 
| take 100 
| sort by TimeGenerated asc, CorrelationId 
| distinct  UserName

Below gives me a session duration for a single user, but i have to manually type in the UserName

let Events = WVDConnections | where UserName == "userupn" ;
Events
| where State == "Connected"
| project CorrelationId , UserName, ResourceAlias , StartTime=TimeGenerated
| join (Events
| where State == "Completed"
| project EndTime=TimeGenerated, CorrelationId)
on CorrelationId
| project Duration = EndTime - StartTime, ResourceAlias
| sort by Duration asc

How can I combine both queries to get result for each user. If it was powershell or python, i would loop through the list given by 1srt query. Not sure how to do in KQL

Azure Monitor
Azure Monitor

An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.

Azure Virtual Desktop
Azure Virtual Desktop

A Microsoft desktop and app virtualization service that runs on Azure. Previously known as Windows Virtual Desktop.

0 comments No comments

Answer accepted by question author

Stanislav Zhelyazkov 29,586 Reputation points MVP Volunteer Moderator
2023-01-17T14:20:17.61+00:00

Hi,

I think something like this would do the work:

let Events = WVDConnections  ;
Events
| where State == "Connected"
| project CorrelationId , UserName, ResourceAlias , StartTime=TimeGenerated
| join (Events
| where State == "Completed"
| project EndTime=TimeGenerated, CorrelationId, UserName)
on CorrelationId, UserName
| project Duration = EndTime - StartTime, ResourceAlias, UserName
| sort by Duration asc

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

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.