**Contents:**

Computes the rolling list of values forward or backward of the current row within the specified column and returns an array of these values.

- If an input value is missing or null, it is not factored in the computation. For example, for the first row in the dataset, the rolling count of distinct values of previous values is undefined.
The row from which to extract a value is determined by the order in which the rows are organized based on the

`order`

parameter.If you are working on a randomly generated sample of your dataset, the values that you see for this function might not correspond to the values that are generated on the full dataset during job execution.

- The function takes a column name and three optional integer parameters that determine the maximum number of values and the window backward and forward of the current row.
- By default, the list is limited to
`1000`

values. To change the maximum number of values, specify a value for the`limit`

parameter. - For the window parameters, the default values are
`-1`

and`0`

, which computes the rolling function from the current row back to the first row of the dataset.

- By default, the list is limited to
- This function works with the Window transform. See Window Transform.

For more information on a non-rolling version of this function, see LIST Function.

**Wrangle vs. SQL:** This function is part of Wrangle
, a proprietary data transformation language. Wrangle
is not SQL. For more information, see Wrangle Language.

## Basic Usage

**Column example:**

rollinglist(myCol)

**Output: **Returns the rolling list of values in the `myCol`

column from the first row of the dataset to the current one.

**Rows before example:**

rollinglist(myNumber, 5, 20)

**Output:** Returns the rolling list of values of the current row and the twenty previous row values in the `myNumber`

column, with a limit of 5 total values.

**Rows before and after example:**

rollinglist(myNumber, 20, 299, 200)

**Output:** Returns the rolling list of values from the previous 299 rows, the current row value, and the 200 rows after the current one in the `myNumber`

column, with a limit of 20 total values.

## Syntax and Arguments

rollinglist(col_ref, rowsBefore_integer, rowsAfter_integer) order: order_col [group: group_col]

Argument | Required? | Data Type | Description |
---|---|---|---|

col_ref | Y | string | Name of column whose values are applied to the function |

limit_int | N | integer | Maximum number of values to extract into the list array. From `1` to `1000` . |

rowsBefore_integer | N | integer | Number of rows before the current one to include in the computation |

rowsAfter_integer | N | integer | Number of rows after the current one to include in the computation |

For more information on the `order`

and `group`

parameters, see Window Transform.

For more information on syntax standards, see Language Documentation Syntax Notes.

### col_ref

Name of the column whose values are used to compute the function.

- Multiple columns and wildcards are not supported.

**Usage Notes:**

Required? | Data Type | Example Value |
---|---|---|

Yes | String (column reference to Integer or Decimal values) | `myColumn` |

### limit_int

Non-negative integer that defines the maximum number of values to extract into the list array.

**NOTE: **If specified, this value must between 1 and 1000, inclusive.

**NOTE: **Do not use the limiting argument in a `LIST`

function call on a flat aggregate, in which all values in a column have been inserted into a single cell. In this case, you might be able to use the limit argument if you also specify a `group`

parameter. Misuse of the `LIST`

function can cause the application to crash.

**Usage Notes:**

Required? | Data Type | Example Value |
---|---|---|

No | Integer | `50` |

### rowsBefore_integer, rowsAfter_integer

Integers representing the number of rows before or after the current one from which to compute the rolling function, including the current row. For example, if the first value is `5`

, the current row and the four rows after it are used in the computation. Negative values for `k`

compute the rolling average from rows preceding the current one.

`rowBefore=1`

generates the current row value only.`rowBefore=-1`

uses all rows preceding the current one.- If
`rowsAfter`

is not specified, then the value`0`

is applied. - If a
`group`

parameter is applied, then these parameter values should be no more than the maximum number of rows in the groups.

**Usage Notes:**

Required? | Data Type | Example Value |
---|---|---|

No | Integer | `4` |

## Examples

**Tip:** For additional examples, see Common Tasks.

### Example - Recent Finishers by Boat Type

The following dataset includes the finishing times for each boat in a race. As part of the race, each boat may be assigned one or more penalties in terms of seconds. So, the total time for the race is computed by adding two columns.

You are interested in the list of recent finishers by each finishing time.

**Source:**

id | pilotName | boatType | raceTime | racePenalties |
---|---|---|---|---|

1 | Schmidt | Sunfish | 4573.8 | 53 |

2 | Bolt | Laser | 4934.21 | 11 |

3 | Masters | Force 5 | 4446.89 | 70 |

4 | Jamison | Force 5 | 4355.79 | 31 |

5 | Williams | Sunfish | 4675.86 | 15 |

6 | Hobart | Laser | 5077.5 | 50 |

7 | Millingham | Laser | 4940.09 | 54 |

8 | Nelson | Force 5 | 5116.14 | 56 |

9 | Greene | Sunfish | 5105.94 | 5 |

10 | Danielson | Laser | 4964.03 | 18 |

11 | Cooper | Force 5 | 5281.55 | 13 |

12 | Stevens | Laser | 5176.35 | 0 |

13 | Young | Sunfish | 5038.11 | 16 |

14 | Thompson | Force 5 | 5252.9 | 62 |

15 | McDonald | Laser | 5052.24 | 20 |

16 | O'Roarke | Sunfish | 5080.76 | 45 |

17 | Collins | Sunfish | 5176.09 | 10 |

18 | Wright | Laser | 5391.61 | 34 |

19 | Black | Sunfish | 5023.32 | 32 |

20 | Bush | Force 5 | 5200.37 | 28 |

**Transformation:**

Compute the total time for each racer by summing the `raceTime`

column and the `racePenalties`

column:

Transformation Name | `New formula` |
---|---|

Parameter: Formula type | `Single row formula` |

Parameter: raceTime + racePenalties | `FCTN(input)` |

Parameter: New column name | `'totalRaceTime'` |

You can then compute the list of recent finishers by boat type, automatically sorting the generated lists by the `totalRaceTime`

column:

Transformation Name | `New formula` |
---|---|

Parameter: Formula type | `Multiple row formula` |

Parameter: Formula | `rollinglist(boatType, 10, 4, 0)` |

Parameter: Order rows by | `totalRaceTime` |

Parameter: New column name | `'last5FinisherBoatTypes'` |

**Results:**

id | pilotName | boatType | last5FinisherBoatTypes | raceTime | racePenalties | totalRaceTime |
---|---|---|---|---|---|---|

4 | Jamison | Force 5 | ["Force 5"] | 4355.79 | 31 | 4386.79 |

3 | Masters | Force 5 | ["Force 5","Force 5"] | 4446.89 | 70 | 4516.89 |

1 | Schmidt | Sunfish | ["Force 5","Force 5","Sunfish"] | 4573.8 | 53 | 4626.8 |

5 | Williams | Sunfish | ["Force 5","Force 5","Sunfish","Sunfish"] | 4675.86 | 15 | 4690.86 |

2 | Bolt | Laser | ["Force 5","Force 5","Sunfish","Sunfish","Laser"] | 4934.21 | 11 | 4945.21 |

10 | Danielson | Laser | ["Force 5","Sunfish","Sunfish","Laser","Laser"] | 4964.03 | 18 | 4982.03 |

7 | Millingham | Laser | ["Sunfish","Sunfish","Laser","Laser","Laser"] | 4940.09 | 54 | 4994.09 |

13 | Young | Sunfish | ["Sunfish","Laser","Laser","Laser","Sunfish"] | 5038.11 | 16 | 5054.11 |

19 | Black | Sunfish | ["Laser","Laser","Laser","Sunfish","Sunfish"] | 5023.32 | 32 | 5055.32 |

15 | McDonald | Laser | ["Laser","Laser","Sunfish","Sunfish","Laser"] | 5052.24 | 20 | 5072.24 |

9 | Greene | Sunfish | ["Laser","Sunfish","Sunfish","Laser","Sunfish"] | 5105.94 | 5 | 5110.94 |

16 | O'Roarke | Sunfish | ["Sunfish","Sunfish","Laser","Sunfish","Sunfish"] | 5080.76 | 45 | 5125.76 |

6 | Hobart | Laser | ["Sunfish","Laser","Sunfish","Sunfish","Laser"] | 5077.5 | 50 | 5127.5 |

8 | Nelson | Force 5 | ["Laser","Sunfish","Sunfish","Laser","Force 5"] | 5116.14 | 56 | 5172.14 |

12 | Stevens | Laser | ["Sunfish","Sunfish","Laser","Force 5","Laser"] | 5176.35 | 0 | 5176.35 |

17 | Collins | Sunfish | ["Sunfish","Laser","Force 5","Laser","Sunfish"] | 5176.09 | 10 | 5186.09 |

20 | Bush | Force 5 | ["Laser","Force 5","Laser","Sunfish","Force 5"] | 5200.37 | 28 | 5228.37 |

11 | Cooper | Force 5 | ["Force 5","Laser","Sunfish","Force 5","Force 5"] | 5281.55 | 13 | 5294.55 |

14 | Thompson | Force 5 | ["Laser","Sunfish","Force 5","Force 5","Force 5"] | 5252.9 | 62 | 5314.9 |

18 | Wright | Laser | ["Sunfish","Force 5","Force 5","Force 5","Laser"] | 5391.61 | 34 | 5425.61 |

This page has no comments.