Need help in KQL query to get the count from Azure logs.

Sonika Sahu 20 Reputation points
2025-06-14T15:14:33.55+00:00

I have requirement where Count MSAGEPASSKEYS_CANCELPROCESS_INITIATED event only if it appears alone in a session (i.e., not with PasskeyAdd-Success).

If both MSAGEPASSKEYS_CANCELPROCESS_INITIATED and PasskeyAdd-Success are present in the same session, only count PasskeyAdd-Success Event.

I've created below KQL but it's not working as expected.

AppEvents | where Name contains "MSAGEPASSKEYS_CANCELPROCESS_INITIATED" | project Event1 = Name, obj = tostring(Properties.ObjectId), session = tostring(Properties.CorrelationId) | distinct Event1, obj, session | join kind=leftouter (AppEvents | where Name = "MSAGEPASSKEYS_CANCELPROCESS_INITIATED" and Name != "PasskeyAdd-Success" | project Event1 = Name, obj = tostring(Properties.ObjectId), session = tostring(Properties.CorrelationId)) on session | distinct Event1, obj | extend Event1 = replace_string(Event1, 'MSAGEPASSKEYS_CANCELPROCESS_INITIATED', '6-cancel journey initated') | summarize count() by Event1 | sort by Event1 asc

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,645 questions
{count} votes

Accepted answer
  1. Marcin Policht 49,640 Reputation points MVP Volunteer Moderator
    2025-06-14T16:44:54.8466667+00:00

    Try the following

    AppEvents
    | where Name in ("MSAGEPASSKEYS_CANCELPROCESS_INITIATED", "PasskeyAdd-Success", "PasskeyRemove-Success")
    | extend obj = tostring(Properties.ObjectId), session = tostring(Properties.CorrelationId)
    | summarize EventList = make_set(Name) by session, obj
    | extend 
        HasCancel = EventList has "MSAGEPASSKEYS_CANCELPROCESS_INITIATED",
        HasAdd = EventList has "PasskeyAdd-Success",
        HasRemove = EventList has "PasskeyRemove-Success"
    | extend FinalEvent = iff(HasAdd, "PasskeyAdd-Success",
                          iff(HasRemove, "PasskeyRemove-Success",
                          iff(HasCancel, "MSAGEPASSKEYS_CANCELPROCESS_INITIATED", "Other")))
    | where FinalEvent != "Other"
    | summarize count() by FinalEvent
    | sort by FinalEvent asc
    

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin


0 additional answers

Sort by: Most helpful

Your answer

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