series_moving_avg_fl()
Applies to: ✅ Azure Data Explorer ✅ Azure Monitor ✅ Microsoft Sentinel
Applies a moving average filter on a series.
The function series_moving_avg_fl()
is a user-defined function (UDF) that takes an expression containing a dynamic numerical array as input and applies on it a simple moving average filter.
Syntax
series_moving_avg_fl(
y_series,
n [,
center ])
Learn more about syntax conventions.
Parameters
Name | Type | Required | Description |
---|---|---|---|
y_series | dynamic |
✔️ | An array cell of numeric values. |
n | int |
✔️ | The width of the moving average filter. |
center | bool |
Indicates whether the moving average is either applied symmetrically on a window before and after the current point or applied on a window from the current point backwards. By default, center is false . |
Function definition
You can define the function by either embedding its code as a query-defined function, or creating it as a stored function in your database, as follows:
Define the function using the following let statement. No permissions are required.
Important
A let statement can't run on its own. It must be followed by a tabular expression statement. To run a working example of series_moving_avg_fl()
, see Example.
let series_moving_avg_fl = (y_series:dynamic, n:int, center:bool=false)
{
series_fir(y_series, repeat(1, n), true, center)
};
// Write your query to use the function here.
Example
The following example uses the invoke operator to run the function.
To use a query-defined function, invoke it after the embedded function definition.
let series_moving_avg_fl = (y_series:dynamic, n:int, center:bool=false)
{
series_fir(y_series, repeat(1, n), true, center)
};
//
// Moving average of 5 bins
//
demo_make_series1
| make-series num=count() on TimeStamp step 1h by OsVer
| extend num_ma=series_moving_avg_fl(num, 5, True)
| render timechart
Output