Query Details
let _RetentionDays = 90;
let _WarningDays = 7;
Usage
| where TimeGenerated > ago(365d)
| summarize OldestRecord = min(TimeGenerated) by DataType
| extend
AgeDays = datetime_diff('day', now(), OldestRecord),
DaysUntilPurge = _RetentionDays - datetime_diff('day', now(), OldestRecord)
| where DaysUntilPurge >= 0 and DaysUntilPurge <= _WarningDays
| extend
PurgeDate = OldestRecord + totimespan(strcat(tostring(_RetentionDays), "d")),
Urgency = case(
DaysUntilPurge <= 1, "IMMINENT - Purge within 24h",
DaysUntilPurge <= 3, "URGENT - Purge within 3 days",
"WARNING - Purge within 7 days"
)
| project DataType, OldestRecord, PurgeDate, DaysUntilPurge, Urgency
| order by DaysUntilPurge asc
This query is designed to monitor data retention and provide warnings for data that is approaching its purge date. Here's a simple breakdown of what it does:
Set Parameters: It defines two variables: _RetentionDays (90 days) and _WarningDays (7 days).
Filter Data: It looks at data generated in the last 365 days.
Identify Oldest Records: For each data type, it finds the oldest record's timestamp.
Calculate Age and Purge Timing:
Filter for Warnings: It only keeps records that are within the warning period (0 to 7 days before purge).
Determine Purge Date and Urgency:
Output: It displays the data type, the oldest record date, the purge date, days until purge, and urgency level, sorted by how soon the purge will occur.
In summary, this query helps identify and prioritize data that needs attention because it is nearing its retention limit and will soon be purged.

David Alonso
Released: April 8, 2026
Tables
Keywords
Operators