Bin

bin

The bin function buckets the first argument into buckets the size of the second argument.

Spec

bin(arg0, arg1)

Parameters

arg0 - Input parameter to bucketize.
arg1 - Bucket size parameter. Must be mathematically compatible with arg0.

Return Value

The bucketed result. arg0 after it has been bucketed.

Example

range val from 1 to 5 step 1
| project val, bin(val, 2)
valbin_val_const_int
10
22
32
44
54

The bin function is very useful for bucketing during aggregations.

range val from 1 to 5 step 1
| summarize count() by bin(val, 2)
bin_val_const_intcount
01
22
42

bin

Rounds down a datetime or number into equal-sized bins.

Syntax

bin(Expression, Size)

Examples

Bucket events into 5-minute windows:

logs
| summarize count() by bin(timestamp, 5m)

Bucket numeric values:

metrics
| summarize avg(value) by bin(value, 10)