# PREVIOUS
URL: https://docs.valsight.ai/previous/
Description: The PREVIOUS function returns the previous period value of a node with a defined base case, enabling loop-style calculations along the time dimension.
**Category:** [Rollforward & time series](/rollforward-time-series/)

> The previous function is almost never necessary and has **considerable performance and usability disadvantages** over the [ROLLFORWARD](/rollforward/) function. Its usage is not advised, unless you absolutely must - contact the Valsight support for information on your specific problem to evaluate if it can be modelled with a ROLLFORWARD instead.

## Overview

The **PREVIOUS** function **returns the previous period value of a node, except for the base period where it returns the value of the base node**. All effects applied between the node and the base node therefore cumulate over the year. The function can be used to create models where the value of a node depends on the result for the previous period of a node higher in the value driver tree, thereby creating a loop that is resolved along the time dimension. An example is provided below, where the `'Base Cost'` node depends on the final `'Cost'` of the previous year, calculating the costs based on the costs of the previous year with the two drivers inflation and productivity.

Use this function when you need loop-style logic with a defined base case rather than a simple previous-period comparison.

## Syntax

`PREVIOUS('Node', "Level", 'BaseNode', "BaseValue")`

## Parameters

| Parameter     | Description                                                                                                      | Type           | Required |
| ------------- | ---------------------------------------------------------------------------------------------------------------- | -------------- | -------- |
| **Node**      | Input node of which the previous period value is taken, for example `'Cost'`.                                    | Node reference | Yes      |
| **Level**     | The time level that defines the previous value, for example `"Year"` where the previous of `"2026"` is `"2025"`. | Level name     | Yes      |
| **BaseNode**  | Input node that is used to get the value of the node for the base period, for example `'Initial Cost'`.          | Node reference | Yes      |
| **BaseValue** | The value describing the base period, for example `"2025"`.                                                      | Level value    | Yes      |

## Watch out

When using the PREVIOUS function, the following limitations apply to all nodes between `'Node'` and `'BaseNode'`:

* No manipulation of time, for example by using `SHIFT`.
* All nodes must have the time level used for the loop.
* `'Node'` and `'BaseNode'` must have the same levels.

## Example

### Loop logic with an explicit base period

This example shows how PREVIOUS creates a loop along the time dimension by taking the prior year's result and using a fixed base period to start the calculation.

**Input node:** `'Initial Cost'`

| Year | Cost |
| ---- | ---- |
| 2025 | 100  |

**Input node:** `'Productivity Change'`

| Year | Productivity Change |
| ---- | ------------------- |
| 2025 | 0%                  |
| 2026 | 20%                 |
| 2027 | 20%                 |
| 2028 | 20%                 |

**Input node:** `'Cost Inflation'`

| Year | Cost Inflation |
| ---- | -------------- |
| 2025 | 0%             |
| 2026 | 10%            |
| 2027 | 10%            |
| 2028 | 10%            |

**Formula:** `PREVIOUS('Cost', "Year", 'Initial Cost', "2025")`

| Year | PREVIOUS Result |
| ---- | --------------- |
| 2025 | 100             |
| 2026 | 100             |
| 2027 | 130             |
| 2028 | 169             |

**Formula:** `'Base Cost' * (EXPAND(1, "Year") + 'Cost Inflation' + 'Productivity Change')`

| Year | Cost  |
| ---- | ----- |
| 2025 | 100   |
| 2026 | 130   |
| 2027 | 169   |
| 2028 | 219.7 |

## Related

| Function                     | When to use instead                                                                                                   |
| ---------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| [ROLLFORWARD](/rollforward/) | When the same logic should be modelled in a more modern and performant way instead of relying on PREVIOUS loop logic. |
| [PY](/py/)                   | When you only need a simple previous-year reference instead of loop-style logic with an explicit base case.           |
