To create a custom detection rule in Microsoft Defender XDR , your KQL query must produce a single record per entity (such as per DeviceId ) representing the latest event. Using the arg_max() function ensures that only the most recent event per entity is captured. The pattern follows Microsoft's best practice for detection rules: DeviceEvents | where ActionType == " AntivirusDetection " | summarize (Timestamp, ReportId)=arg_max(Timestamp, ReportId), count() by DeviceId This ensures the query returns the latest detection for each device, which Defender XDR can then evaluate as a detection trigger. # Answer: B. summarize (Timestamp, ReportId)=arg_max(Timestamp, ReportId), count() by DeviceId