

# Window functions
<a name="recipe-actions.functions.window"></a>

Following, find reference topics for window functions that work with recipe actions.

**Topics**
+ [FILL](recipe-actions.functions.FILL.md)
+ [NEXT](recipe-actions.functions.NEXT.md)
+ [PREV](recipe-actions.functions.PREV.md)
+ [ROLLING\$1AVERAGE](recipe-actions.functions.ROLLING_AVERAGE.md)
+ [ROLLING\$1COUNT\$1A](recipe-actions.functions.ROLLING_COUNT_A.md)
+ [ROLLING\$1KTH\$1LARGEST](recipe-actions.functions.ROLLING_KTH_LARGEST.md)
+ [ROLLING\$1KTH\$1LARGEST\$1UNIQUE](recipe-actions.functions.ROLLING_KTH_LARGEST_UNIQUE.md)
+ [ROLLING\$1MAX](recipe-actions.functions.ROLLING_MAX.md)
+ [ROLLING\$1MIN](recipe-actions.functions.ROLLING_MIN.md)
+ [ROLLING\$1MODE](recipe-actions.functions.ROLLING_MODE.md)
+ [ROLLING\$1STANDARD\$1DEVIATION](recipe-actions.functions.ROLLING_STANDARD_DEVIATION.md)
+ [ROLLING\$1SUM](recipe-actions.functions.ROLLING_SUM.md)
+ [ROLLING\$1VARIANCE](recipe-actions.functions.ROLLING_VARIANCE.md)
+ [ROW\$1NUMBER](recipe-actions.functions.ROW_NUMBER.md)
+ [SESSION](recipe-actions.functions.SESSION.md)

# FILL
<a name="recipe-actions.functions.FILL"></a>

Returns a new column based on a specified source column. For any missing or null values in the source column, `FILL` chooses the most recent nonblank value from a window of rows before and after the source value in question. The chosen value is then placed in the new column.

**Parameters**
+ `sourceColumn` – The name of an existing column.
+ `numRowsBefore` – A number of rows before the current source row, representing the start of the window.
+ `numRowsAfter` – A number of rows after the current source row, representing the end of the window.
+ `targetColumn` – A name for the newly created column.

**Example**  
  

```
{
    "Action": {
        "Operation": "FILL",
        "Parameters": {
            "numRowsAfter": "10",
            "numRowsBefore": "10",
            "sourceColumn": "last_name",
            "targetColumn": "last_name_FILL"
        }
    }
}
```

# NEXT
<a name="recipe-actions.functions.NEXT"></a>

Returns a new column, where each value represents a value that is *n* rows later in the source column. 

**Parameters**
+ `sourceColumn` – The name of an existing column.
+ `numRows` – A value that represents *n* rows earlier in the source column. For example, if `numRows` is 3, then `NEXT` uses the third-next `sourceColumn` value as the new `targetColumn` value.
+ `targetColumn` – A name for the newly created column.

**Example**  
  

```
{
    "Action": {
        "Operation": "NEXT",
        "Parameters": {
            "numRows": "1",
            "sourceColumn": "age",
            "targetColumn": "age_NEXT"
        }
    }
}
```

# PREV
<a name="recipe-actions.functions.PREV"></a>

Returns a new column, where each value represents a value that is *n* rows earlier in the source column.

**Parameters**
+ `sourceColumn` – The name of an existing column.
+ `numRows` – A value that represents *n* rows earlier in the source column. For example, if `numRows` is 3, then `PREV` uses the third-previous `sourceColumn` value as the new `targetColumn` value.
+ `targetColumn` – A name for the newly created column.

**Example**  
  

```
{
    "Action": {
        "Operation": "PREV",
        "Parameters": {
            "numRows": "1",
            "sourceColumn": "age",
            "targetColumn": "age_PREV"
        }
    }
}
```

# ROLLING\$1AVERAGE
<a name="recipe-actions.functions.ROLLING_AVERAGE"></a>

Returns in a new column the rolling average of values from a specified number of rows before to a specified number of rows after the current row in the specified column.

**Parameters**
+ `sourceColumn` – The name of an existing column.
+ `numRowsBefore` – A number of rows before the current source row, representing the start of the window.
+ `numRowsAfter` – A number of rows after the current source row, representing the end of the window.
+ `targetColumn` – A name for the newly created column.

**Example**  
  

```
{
    "Action": {
        "Operation": "ROLLING_AVERAGE",
        "Parameters": {
            "numRowsAfter": "10",
            "numRowsBefore": "10",
            "sourceColumn": "weight_kg",
            "targetColumn": "weight_kg_ROLLING_AVERAGE"
        }
    }
}
```

# ROLLING\$1COUNT\$1A
<a name="recipe-actions.functions.ROLLING_COUNT_A"></a>

Returns in a new column the rolling count of non-null values from a specified number of rows before to a specified number of rows after the current row in the specified column.

**Parameters**
+ `sourceColumn` – The name of an existing column.
+ `numRowsBefore` – A number of rows before the current source row, representing the start of the window.
+ `numRowsAfter` – A number of rows after the current source row, representing the end of the window.
+ `targetColumn` – A name for the newly created column.

**Example**  
  

```
{
    "Action": {
        "Operation": "ROLLING_COUNT_A",
        "Parameters": {
            "numRowsAfter": "10",
            "numRowsBefore": "10",
            "sourceColumn": "weight_kg",
            "targetColumn": "weight_kg_ROLLING_COUNT_A"
        }
    }
}
```

# ROLLING\$1KTH\$1LARGEST
<a name="recipe-actions.functions.ROLLING_KTH_LARGEST"></a>

Returns in a new column the rolling *k*th largest value from a specified number of rows before to a specified number of rows after the current row in the specified column.

**Parameters**
+ `sourceColumn` – The name of an existing column.
+ `numRowsBefore` – A number of rows before the current source row, representing the start of the window.
+ `numRowsAfter` – A number of rows after the current source row, representing the end of the window.
+ `value` – The value for *k*.
+ `targetColumn` – A name for the newly created column.

**Example**  
  

```
  {
    "Action": {
      "Operation": "ROLLING_KTH_LARGEST",
      "Parameters": {
        "sourceColumn": "weight_kg",
        "numRowsBefore": "5",
        "numRowsAfter": "5",
        "value": "3"
        "targetColumn": "weight_kg_ROLLING_KTH_LARGEST"
      }
    }
  }
```

# ROLLING\$1KTH\$1LARGEST\$1UNIQUE
<a name="recipe-actions.functions.ROLLING_KTH_LARGEST_UNIQUE"></a>

Returns in a new column the rolling unique *k*th largest value from a specified number of rows before to a specified number of rows after the current row in the specified column.

**Parameters**
+ `sourceColumn` – The name of an existing column.
+ `numRowsBefore` – A number of rows before the current source row, representing the start of the window.
+ `numRowsAfter` – A number of rows after the current source row, representing the end of the window.
+ `value` – The value for *k*.
+ `targetColumn` – A name for the newly created column.

**Example**  
  

```
  {
    "Action": {
      "Operation": "ROLLING_KTH_LARGEST_UNIQUE",
      "Parameters": {
        "sourceColumn": "games_played",
        "numRowsBefore": "3",
        "numRowsAfter": "3",
        "value": "5",
        "targetColumn": "weight_kg_ROLLING_KTH_LARGEST_UNIQUE"
      }
    }
  }
```

# ROLLING\$1MAX
<a name="recipe-actions.functions.ROLLING_MAX"></a>

Returns in a new column the rolling maximum of values from a specified number of rows before to a specified number of rows after the current row in the specified column.

**Parameters**
+ `sourceColumn` – The name of an existing column.

  `numRowsBefore` – A number of rows before the current source row, representing the start of the window.
+ `numRowsAfter` – A number of rows after the current source row, representing the end of the window.
+ `targetColumn` – A name for the newly created column.

**Example**  
  

```
{
    "Action": {
        "Operation": "ROLLING_MAX",
        "Parameters": {
            "numRowsAfter": "10",
            "numRowsBefore": "10",
            "sourceColumn": "weight_kg",
            "targetColumn": "weight_kg_ROLLING_MAX"
        }
    }
}
```

# ROLLING\$1MIN
<a name="recipe-actions.functions.ROLLING_MIN"></a>

Returns in a new column the rolling minimum of values from a specified number of rows before to a specified number of rows after the current row in the specified column.

**Parameters**
+ `sourceColumn` – The name of an existing column.

  `numRowsBefore` – A number of rows before the current source row, representing the start of the window.
+ `numRowsAfter` – A number of rows after the current source row, representing the end of the window.
+ `targetColumn` – A name for the newly created column.

**Example**  
  

```
{
    "Action": {
        "Operation": "ROLLING_MIN",
        "Parameters": {
            "numRowsAfter": "10",
            "numRowsBefore": "10",
            "sourceColumn": "weight_kg",
            "targetColumn": "weight_kg_ROLLING_MIN"
        }
    }
}
```

# ROLLING\$1MODE
<a name="recipe-actions.functions.ROLLING_MODE"></a>

Returns in a new column the rolling mode (most common value) from a specified number of rows before to a specified number of rows after the current row in the specified column.

**Parameters**
+ `sourceColumn` – The name of an existing column.
+ `numRowsBefore` – A number of rows before the current source row, representing the start of the window.
+ `numRowsAfter` – A number of rows after the current source row, representing the end of the window.
+ modeType – The modal function to apply to the window. Valid values are `NONE`, `MINIMUM`, `MAXIMUM`, and `AVERAGE`.
+ `targetColumn` – A name for the newly created column.

**Example**  
  

```
{
    "Action": {
        "Operation": "ROLLING_MODE",
        "Parameters": {
            "modeType": "MINIMUM",
            "numRowsAfter": "10",
            "numRowsBefore": "10",
            "sourceColumn": "weight_kg",
            "targetColumn": "weight_kg_ROLLING_MODE"
        }
    }
}
```

# ROLLING\$1STANDARD\$1DEVIATION
<a name="recipe-actions.functions.ROLLING_STANDARD_DEVIATION"></a>

Returns in a new column the rolling standard deviation of values from a specified number of rows before to a specified number of rows after the current row in the specified column.

**Parameters**
+ `sourceColumn` – The name of an existing column.
+ `numRowsBefore` – A number of rows before the current source row, representing the start of the window.
+ `numRowsAfter` – A number of rows after the current source row, representing the end of the window.
+ `targetColumn` – A name for the newly created column.

**Example**  
  

```
{
    "Action": {
        "Operation": "ROLLING_STDEV",
        "Parameters": {
            "numRowsAfter": "10",
            "numRowsBefore": "10",
            "sourceColumn": "weight_kg",
            "targetColumn": "weight_kg_ROLLING_STDEV"
        }
    }
}
```

# ROLLING\$1SUM
<a name="recipe-actions.functions.ROLLING_SUM"></a>

Returns in a new column the rolling sum of values from a specified number of rows before to a specified number of rows after the current row in the specified column. 

**Parameters**
+ `sourceColumn` – The name of an existing column.

  `numRowsBefore` – A number of rows before the current source row, representing the start of the window.
+ `numRowsAfter` – A number of rows after the current source row, representing the end of the window.
+ `targetColumn` – A name for the newly created column.

**Example**  
  

```
{
    "Action": {
        "Operation": "ROLLING_SUM",
        "Parameters": {
            "numRowsAfter": "10",
            "numRowsBefore": "10",
            "sourceColumn": "weight_kg",
            "targetColumn": "weight_kg_ROLLING_SUM"
        }
    }
}
```

# ROLLING\$1VARIANCE
<a name="recipe-actions.functions.ROLLING_VARIANCE"></a>

Returns in a new column the rolling variance of values from a specified number of rows before to a specified number of rows after the current row in the specified column.

**Parameters**
+ `sourceColumn` – The name of an existing column.
+ `numRowsBefore` – A number of rows before the current source row, representing the start of the window.
+ `numRowsAfter` – A number of rows after the current source row, representing the end of the window.
+ `targetColumn` – A name for the newly created column.

**Example**  
  

```
{
    "Action": {
        "Operation": "ROLLING_VAR",
        "Parameters": {
            "numRowsAfter": "10",
            "numRowsBefore": "10",
            "sourceColumn": "weight_kg",
            "targetColumn": "weight_kg_ROLLING_VAR"
        }
    }
}
```

# ROW\$1NUMBER
<a name="recipe-actions.functions.ROW_NUMBER"></a>

Returns in a new column a session identifier based on a window created by column names from "group by" and "order by" statements.

**Parameters**
+ `groupByColumns` – A JSON-encoded string describing the "group by" columns.
+ `orderByColumns` – A JSON-encoded string describing the "order by" columns.
+ `targetColumn` – A name for the newly created column.

**Example**  
  

```
{
    "Action": {
        "Operation": "ROW_NUMBER",
        "Parameters": {
            "groupByColumns": "[\"is public domain\"]",
            "orderByColumns": "[\"dimensions\"]",
            "targetColumn": "Row number"
        }
    }
}
```

# SESSION
<a name="recipe-actions.functions.SESSION"></a>

Returns in a new column a session identifier based on a window created by column names from "group by" and "order by" statements. 

**Parameters**
+ `sourceColumn` – The name of an existing column.
+ `units` – A unit of measure for describe the session length. Valid values are `MONTHS`, `YEARS`, `MILLISECONDS`, `QUARTERS`, `HOURS`, `MICROSECONDS`, `WEEKS`, `SECONDS`, `DAYS`, and `MINUTES`.
+ `value` – The number of `units` to define the time period.
+ `groupByColumns` – A JSON-encoded string describing the "group by" columns.
+ `orderByColumns` – A JSON-encoded string describing the "order by" columns.
+ `targetColumn` – A name for the newly created column.

**Example**  
  

```
{
    "Action": {
        "Operation": "SESSION",
        "Parameters": {
            "sourceColumn": "object number",
            "units": "MINUTES",
            "value": "10",
            "groupByColumns": "[\"is public domain\"]",
            "orderByColumns": "[\"dimensions\"]",
            "targetColumn": "object number_SESSION",
        }
    }
}
```