---
url: /cube-functions/sequence.md
description: This function is typically used in rolling balance calculations.
---

# SEQUENCE

This function is typically used in rolling balance calculations. In example you might have a measures dimension tracking the number of subscribed customers which in any given period has an Opening Balance, New Subscriptions, Churning Subscriptions which added together results in a Closing Balance. You can use the SEQUENCE function on the Opening Balance element to make it equal to the prior periods Closing Balance

```js
SEQUENCE(dimension, hierarchy, sequency_shift, relative_location)
```

#### Parameters

* `dimension` - The dimension to source the sequence from.
* `hierarchy` - The hierarchy in the specified dimension to source the sequence from.
* `sequency_shift` - A numeric value denoting how many items to move (shift) in the sequency. (for rolling monthly balances this may be -1)
* `relative_location` - The relative location in the resulting location.

#### Examples

```js
SEQUENCE("Time", "Month List", -1, ["Closing Balance"])
```

**Note:** This will return the value from the same cube from the prior month element.
