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) | val | bin_val_const_int |
|---|---|
| 1 | 0 |
| 2 | 2 |
| 3 | 2 |
| 4 | 4 |
| 5 | 4 |
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_int | count |
|---|---|
| 0 | 1 |
| 2 | 2 |
| 4 | 2 |
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)