Calculates a rolling average over a range using a fixed window size
=LET(
v, values,
n, ROWS(v),
w, window_size+0,
IF(
OR(w<1, n=0),
,
MAP(
SEQUENCE(n),
LAMBDA(i,
IF(
i<w,
AVERAGE(INDEX(v, 1, 1):INDEX(v, i, 1)),
AVERAGE(INDEX(v, i-w+1, 1):INDEX(v, i, 1))
)
)
)
)
)This function generates a rolling (moving) average series from a list of values using a fixed window size. It's useful for smoothing trends in time series data like daily metrics, revenue, temperatures, or other noisy sequences. To use it, place your values in a single column (for example A2:A100), choose a window size (for example, 7 for a rolling weekly average), then enter =ROLLING_AVERAGE(A2:A100, 7) in an empty cell. The formula will spill a new column of results where each row shows the average of the most recent window_size values up to that row. For example, with values in A2:A11 and window size "3", the output row for A6 is the average of A4:A6.
Use the inputs below to create ROLLING_AVERAGE as a reusable custom function in Google Sheets.
Learn how to add custom functions to Google SheetsROLLING_AVERAGE
Calculates a rolling average over a range using a fixed window size
=LET( v, values, n, ROWS(v), w, window_size+0, IF( OR(w<1, n=0), , MAP( SEQUENCE(n), LAMBDA(i, IF( i<w, AVERAGE(INDEX(v, 1, 1):INDEX(v, i, 1)), AVERAGE(INDEX(v, i-w+1, 1):INDEX(v, i, 1)) ) ) ) ) )
values
window_size
Range of numeric values to average
A2:A100
Size of the rolling window (must be >= 1)
7
Other functions in the same category: Mathematical & Statistical
Calculates body mass index (BMI) from weight and height
Constrains a number between a minimum and maximum value
Returns the sigmoid of a number (logistic function)
Calculates Basal Metabolic Rate using the revised Harris-Benedict equation in imperial units
Calculates Basal Metabolic Rate using the revised Harris-Benedict equation in metric units
Calculate the percentage change between two values
Named functions enable the creation of custom, reusable formulas that mimic built-in functions, streamlining calculations and data manipulations. These functions simplify complex formulas, making spreadsheets more readable and less prone to errors. By encapsulating intricate logic within a single function call, they enhance consistency across your data. Utilizing named functions reduces the need to write lengthy formulas repeatedly, thereby improving workflow efficiency and productivity in data analysis and management.
Download and import — fastest way to add the function but does not include argument descriptions and examples
Follow these simple steps to download and import a function into your spreadsheet. This method is the quickest and easiest way to add the named function to your Google Sheets document, but will not include the argument description and examples.
Once added, the function will be ready to use in your document like any other built-in function. Simply type the function name and provide the required inputs to use it in your calculations.
Copy and paste — copy and paste each property one at a time
Follow these simple steps to integrate a custom named function into your spreadsheet:
Once added, the function will be ready to use in your document like any other built-in function. Simply type the function name and provide the required inputs to use it in your calculations.