Berserk Docs
Scalar FunctionsMath Functions

bin_auto

Automatically bins datetime values into human-friendly intervals based on the

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:00Z100
2024-01-01T01:00:00Z200
2024-01-01T02:00:00Z150
2024-01-01T03:00:00Z300

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:00Z300
2024-01-01T02:00:00Z450

On this page