# Window versus Grid Aggregate Functions

> The Window Aggregate functions are similar to the corresponding Grid Aggregate functions except that the interval indicates the next N elements from the input sequence. So for example, given a sequence of 12 elements with interval = 7, whereas the grid_agg_avg function would calculate the average for the elements`{0,1,2,3,4,5,6}` then `{7,8,9,10,12,12}`, the window_agg_avg function would calculate the average for the elements `{0,1,2,3,4,5,6}`, then elements `{1,2,3,4,5,6,7}`, then `{2,3,4,5,6,7,8}`, etc. for a total of 12 results.

> Note that whereas the grid_agg functions return result sequences with 2 elements, the window_agg functions return sequences with 12 elements which comprise the “sliding blocks” of 7 elements of which the first interval-1 should be ignored (see the explanation in the note below).

> Note also that there are differing methods for representing “moving windows” of sequence functions. At issue is how to represent results that are computed on less than the number of elements specified as the interval for the window, since the previous interval-1 elements are needed for the computation of each element.

> > For example, consider a sequence of 5 elements as input to a window_agg function with interval of 5. The window for the first 4 result sequences for an interval of 5 will be computed on an incomplete set of 1,2,3 and 4 actual element values. The computation can be illustrated as follows:

> > where the dash “-“ indicates a non-existent element and “0” represents a substituted value. In this case, clearly the only valid result sequence is the last one (highlighted) which has 5 valid input values.

> > There is no “right” way to represent these first four result sequences. But the important point is that the first interval-1 results should be ignored since they don’t represent a complete window.