GitHubContribute in GitHub: Edit online

bin()

Rounds values down to an integer multiple of a given bin size.

Used frequently in combination with summarize by .... If you have a scattered set of values, they will be grouped into a smaller set of specific values.

Null values, a null bin size, or a negative bin size will result in null.

Alias to floor() function.

Syntax

bin(value,roundTo)

Arguments

  • value: A number, date, or timespan.
  • roundTo: The "bin size". A number or timespan that divides value.

Returns

The nearest multiple of roundTo below value.

(toint((value/roundTo))) * roundTo`

Examples

Expression Result
bin(4.5, 1) 4.0
bin(time(16d), 7d) 14d
bin(datetime(1970-05-11 13:45:07), 1d) datetime(1970-05-11)

The following expression calculates a histogram of durations, with a bucket size of 1 second:

events    
    | project original_time
    | where original_time > ago(30d)    
    //--- USER Criteria He
    | summarize Hits=count() by bin(original_time, 1s)

Results

Showing the first 3 rsults from the entire set.

original_time Hits
2023-06-07T11:32:16.000Z 84
2023-06-07T11:32:17.000Z 114
2023-06-07T11:32:18.000Z 92