Query Details
Usage
| where TimeGenerated > ago(365d)
| summarize
OldestRecord = min(TimeGenerated),
NewestRecord = max(TimeGenerated),
TotalMB = round(sum(Quantity), 2),
Records = count()
by DataType
| extend
ObservedRetentionDays = datetime_diff('day', now(), OldestRecord),
DataSpanDays = datetime_diff('day', NewestRecord, OldestRecord),
LastIngestion = NewestRecord,
TablePlan = iff(TotalMB > 0, "Active", "Empty")
| extend
RetentionTier = case(
ObservedRetentionDays >= 365, "1 Year+",
ObservedRetentionDays >= 180, "6 Months+",
ObservedRetentionDays >= 90, "90 Days (Standard)",
ObservedRetentionDays >= 30, "30 Days",
"< 30 Days"
)
| project
DataType, ObservedRetentionDays, DataSpanDays, RetentionTier,
OldestRecord, NewestRecord,
TotalGB = round(TotalMB / 1024.0, 3)
| order by ObservedRetentionDays desc
This KQL query is analyzing data usage over the past year. Here's a simple breakdown of what it does:
Filter Data: It starts by selecting records from the last 365 days.
Summarize Data: For each type of data (DataType), it calculates:
Calculate Additional Metrics:
ObservedRetentionDays: How many days ago the oldest record was generated.DataSpanDays: The number of days between the oldest and newest records.LastIngestion: The timestamp of the most recent record.TablePlan: Indicates if the data type is "Active" (if there's any data) or "Empty" (if there's none).Determine Retention Tier: Assigns a retention category based on how long the data has been retained:
Project and Format Results: It selects and formats the final output to include:
Order Results: Finally, it sorts the results by the number of observed retention days in descending order, showing the data types with the longest retention first.

David Alonso
Released: April 8, 2026
Tables
Keywords
Operators