bin_auto
Automatically bins datetime values into human-friendly intervals based on the query time range.
Targets 750-1500 bins for good visualization granularity, guaranteeing at most 1500 bins.
Selects from these intervals: 1ms, 10ms, 100ms, 250ms, 500ms, 1s, 10s, 15s, 30s, 1m, 5m, 10m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d, 7d.
Example bin sizes for common time ranges:
- 1 second → 1ms bins
- 1 minute → 100ms bins
- 1 hour → 10s bins
- 1 day → 1m bins
- 7 days → 10m bins
- 30 days → 30m bins
- 1 year → 6h bins
If min_span is provided, the final bin size is max(min_span, computed_span).
Internally transformed to bin(field, computed_span) at query compile time.
Differs from Microsoft KQL
Berserk's bin_auto uses a deterministic algorithm that selects from 21
fixed human-friendly intervals, targeting 750-1500 bins. Microsoft's version
uses an opaque server-side algorithm tied to the query_bin_auto_size query
option and may produce different bin sizes for the same time range. The
min_span parameter in Berserk is a second positional argument
(bin_auto(ts, 5m)), whereas Microsoft uses the query option
set query_bin_auto_size = 5m instead.
Syntax
bin_auto(value)Parameters
Prop
Type
Returns: datetime
Syntax
bin_auto(value, min_span)Parameters
Prop
Type
Returns: datetime
Examples
Example 1 — Auto-select bin size based on time range
datatable(ts:datetime, silver:long)[
datetime(2024-01-01), 100,
datetime(2024-01-01T01:00:00), 200,
datetime(2024-01-01T02:00:00), 150,
datetime(2024-01-01T03:00:00), 300
]
| summarize sum(silver) by bin_auto(ts)| ts (datetime) | sum_silver (long) |
|---|---|
| 2024-01-01T00:00:00Z | 100 |
| 2024-01-01T01:00:00Z | 200 |
| 2024-01-01T02:00:00Z | 150 |
| 2024-01-01T03:00:00Z | 300 |
Example 2 — With min_span of 2 hours — bins are at least 2h wide
datatable(ts:datetime, silver:long)[
datetime(2024-01-01), 100,
datetime(2024-01-01T01:00:00), 200,
datetime(2024-01-01T02:00:00), 150,
datetime(2024-01-01T03:00:00), 300
]
| summarize sum(silver) by bin_auto(ts, 2h)| ts (datetime) | sum_silver (long) |
|---|---|
| 2024-01-01T00:00:00Z | 300 |
| 2024-01-01T02:00:00Z | 450 |