> ## Documentation Index
> Fetch the complete documentation index at: https://docs.less.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# Running Interval

> Create custom running calculations

The Running Interval tool can be used to calculate custom running calculations. It can generate simple columns like 30 days running profit, but also other way cooler things like a custom customer acquisition cost metric.

<Frame caption="Configuration: Sum, Revenue column, offset -2, lookahead 3">
  <img className="rounded-md" src="https://mintcdn.com/less-51/am-71qiho-NViN_t/images/tools/running-interval/Illustration.png?fit=max&auto=format&n=am-71qiho-NViN_t&q=85&s=c8503a2389c59509c008e0c8f7ea5b2d" width="1098" height="464" data-path="images/tools/running-interval/Illustration.png" />
</Frame>

<Tip>
  If you're looking for more ways to do row-wise calculations check out the [Compare](/tools/new-columns/compare), [Cumulative](/tools/new-columns/cumulative), or [Loop](/tools/utilities/loop) tool.
</Tip>

### Configuration

<Steps>
  <Step title="Column name">
    The Running Interval tool will create a new column. Use this input to name it.
  </Step>

  <Step title="Running interval column">
    Select the column you want to use for a running interval calculation.
  </Step>

  <Step title="Input offset">
    Input where you want your calculation to begin. Think of this as the row from your current row that your calculation should being. If you input -1 your calculation will always be calculated from your current row - 1 (understood vertically in your dataset).

    <Frame>
      <img className="rounded-md" src="https://mintcdn.com/less-51/am-71qiho-NViN_t/images/tools/running-interval/Offset.png?fit=max&auto=format&n=am-71qiho-NViN_t&q=85&s=21cc651ade7eea6daf76e52a3f5eec63" width="422" height="464" data-path="images/tools/running-interval/Offset.png" />
    </Frame>
  </Step>

  <Step title="Rows to include">
    Input how many rows you want to lookahead (or down in your dataset) from your offset. You can understand this and the previous input as creating a rolling range of data that you consider relevant.

    <Frame>
      <img className="rounded-md" src="https://mintcdn.com/less-51/am-71qiho-NViN_t/images/tools/running-interval/Lookahead.png?fit=max&auto=format&n=am-71qiho-NViN_t&q=85&s=6b7f136019f2726716dc26b28e8d7185" width="538" height="486" data-path="images/tools/running-interval/Lookahead.png" />
    </Frame>
  </Step>

  <Step title="Aggregation function">
    Select how you want to aggregate the range that you have created with your offset and lookahead input. You can choose between sum, average, min, max, count, median and variance.
  </Step>

  <Step title="Group by columns (optional)">
    Select the columns you want to group by. This will create a running interval for each group.
  </Step>
</Steps>

### Example: Simple running sum

Here we have a very simple example where we want to calculate the running sum of our *simple\_int* column.

We want to go back 2 rows and look ahead 3 rows.

We use the following configuration:

<Frame>
  <img className="rounded-md" src="https://mintcdn.com/less-51/qnh8gNMWMbLC5eFp/images/tools/running-interval/Simple.png?fit=max&auto=format&n=qnh8gNMWMbLC5eFp&q=85&s=3ae20c47c7d1c5d3d772ad53f5541203" width="2194" height="1556" data-path="images/tools/running-interval/Simple.png" />
</Frame>

We see that the first two rows are null because we don't have enough rows to lookback. The remaining 3 rows are calculated with this logic:

* Row 3: 1+2+3 = 6
* Row 4: 2+3+4 = 9
* Row 5: 3+4+5 = 12

### Example: 3-month rolling average revenue

In this example, we want to calculate the 3-month rolling average of revenue to get a more even revenue trend and remove the worst seasonality. We want the previous, the current and the next months to be included in the calculation.

In addition, we want to group by segment which in this case is a region (EU vs. US).

We use the following configuration:

<Frame>
  <img className="rounded-md" src="https://mintcdn.com/less-51/qnh8gNMWMbLC5eFp/images/tools/running-interval/Complex.png?fit=max&auto=format&n=qnh8gNMWMbLC5eFp&q=85&s=6c901d6e4397998857c7c01c0d4d253b" width="1982" height="1521" data-path="images/tools/running-interval/Complex.png" />
</Frame>

Try looking at row 3 (Feb, 200, US, 200). Here we implicitly do the following:

* Exclude row 2 because it's the current month and because it's the same region (US).
* So we jump one additional row up until we find an observation within the same group. We include row 1 because it's the same region (US) and it then becomes our previous row/month.
* We include row 3 because it's the current month and because it's the same region (US).
* We skip row 4 because for the same reason as row 2.
* We include row 5 because it's the next month and because it's the same region (US).

Row 1 has a value of 100, row 3 has a value of 200 and row 5 has a value of 300 whereby our average is (100 + 200 + 300) / 3 = 200.
