rolling_percentile plugin

Learn how to use the rolling_percentile plugin to calculate an estimate of the rolling percentile per bin for the specified value column.

Returns an estimate for the specified percentile of the ValueColumn population in a rolling (sliding) BinsPerWindow size window per BinSize.

The plugin is invoked with the evaluate operator.

Syntax

T | evaluate rolling_percentile(ValueColumn, Percentile, IndexColumn, BinSize, BinsPerWindow [, dim1, dim2, …] )

Parameters

NameTypeRequiredDescription
Tstring✔️The input tabular expression.
ValueColumnstring✔️The name of the column used to calculate the percentiles.
Percentileint, long, or real✔️Scalar with the percentile to calculate.
IndexColumnstring✔️The name of the column over which to run the rolling window.
BinSizeint, long, real, datetime, or timespan✔️Scalar with size of the bins to apply over the IndexColumn.
BinsPerWindowint✔️The number of bins included in each window.
dim1, dim2, …stringA list of the dimensions columns to slice by.

Returns

Returns a table with a row per each bin (and combination of dimensions if specified) that has the rolling percentile of values in the window ending at the bin (inclusive). Output table schema is:

IndexColumndim1dim_nrolling_BinsPerWindow_percentile_ValueColumn_Pct

Examples

Rolling 3-day median value per day

The next query calculates a 3-day median value in daily granularity. Each row in the output represents the median value for the last 3 bins (days), including the bin itself.

let T = 
    range idx from 0 to 24 * 10 - 1 step 1
    | project Timestamp = datetime(2018-01-01) + 1h * idx, val=idx + 1
    | extend EvenOrOdd = iff(val % 2 == 0, "Even", "Odd");
T  
| evaluate rolling_percentile(val, 50, Timestamp, 1d, 3)

Output

Timestamprolling_3_percentile_val_50
2018-01-01 00:00:00.000000012
2018-01-02 00:00:00.000000024
2018-01-03 00:00:00.000000036
2018-01-04 00:00:00.000000060
2018-01-05 00:00:00.000000084
2018-01-06 00:00:00.0000000108
2018-01-07 00:00:00.0000000132
2018-01-08 00:00:00.0000000156
2018-01-09 00:00:00.0000000180
2018-01-10 00:00:00.0000000204

Rolling 3-day median value per day by dimension

Same example from above, but now also calculates the rolling window partitioned for each value of the dimension.

let T = 
    range idx from 0 to 24 * 10 - 1 step 1
    | project Timestamp = datetime(2018-01-01) + 1h * idx, val=idx + 1
    | extend EvenOrOdd = iff(val % 2 == 0, "Even", "Odd");
T  
| evaluate rolling_percentile(val, 50, Timestamp, 1d, 3, EvenOrOdd)

Output

TimestampEvenOrOddrolling_3_percentile_val_50
2018-01-01 00:00:00.0000000Even12
2018-01-02 00:00:00.0000000Even24
2018-01-03 00:00:00.0000000Even36
2018-01-04 00:00:00.0000000Even60
2018-01-05 00:00:00.0000000Even84
2018-01-06 00:00:00.0000000Even108
2018-01-07 00:00:00.0000000Even132
2018-01-08 00:00:00.0000000Even156
2018-01-09 00:00:00.0000000Even180
2018-01-10 00:00:00.0000000Even204
2018-01-01 00:00:00.0000000Odd11
2018-01-02 00:00:00.0000000Odd23
2018-01-03 00:00:00.0000000Odd35
2018-01-04 00:00:00.0000000Odd59
2018-01-05 00:00:00.0000000Odd83
2018-01-06 00:00:00.0000000Odd107
2018-01-07 00:00:00.0000000Odd131
2018-01-08 00:00:00.0000000Odd155
2018-01-09 00:00:00.0000000Odd179
2018-01-10 00:00:00.0000000Odd203