# LastNPeriods

The LASTNPERIODS function refers to the values of the node’s last ‘n’ periods. It will give the result as the last 'n' periods' value.

### Syntax

.LASTNPERIODS(n) - > \[number]

### Arguments

<table><thead><tr><th width="146">Arguments</th><th width="124">Datatype</th><th>Description </th></tr></thead><tbody><tr><td>n</td><td>Number</td><td>The integer that is less than the number of periods defined in the model.</td></tr></tbody></table>

### Remarks

This function can only be used after referring a node for which this calculation needs to be done as shown below in the example.

### Example

Consider a scenario where we have interest payments for Jan to Dec. Our objective is to calculate the interest paid in the last 6 months for each month.

<table><thead><tr><th width="159">2022 Periods</th><th>Jan</th><th>Feb</th><th>Mar</th><th>Apr</th><th>May</th><th>Jun</th><th>Jul</th><th>Aug</th><th>Sep</th><th>Oct</th><th>Nov</th><th>Dec</th></tr></thead><tbody><tr><td><mark style="color:orange;">Interest payments</mark></td><td>0</td><td>78.37</td><td>74.06</td><td>69.71</td><td>65.33</td><td>60.91</td><td>56.46</td><td>51.96</td><td>47.43</td><td>42.86</td><td>38.26</td><td>33.61</td></tr></tbody></table>

To achieve this, the following formula should be written in the \[Last 6 period's value] node:

<mark style="color:blue;">**`SUM`**</mark>**`(`**<mark style="color:orange;">**`[Interest payments]`**</mark>**`.`**<mark style="color:blue;">**`LastNPeriods`**</mark>**`(6))`**

We give n as 6 since we want to calculate the last 6 months value. This will calculate the last 6 months value for each period. So for March it will add Jan & Feb, for April it will add Jan to Mar and so on.

### Result

<table data-header-hidden><thead><tr><th width="133">Column1</th><th width="75">Column2</th><th width="75">Column3</th><th width="75">Column4</th><th width="75">Column5</th><th width="75">Column6</th><th width="75">Column7</th><th width="75">Column8</th><th width="75">Column9</th><th width="83">Column10</th><th width="83">Column11</th><th width="83">Column12</th><th width="83">Column13</th></tr></thead><tbody><tr><td>Last 6 period's value</td><td>0</td><td>0</td><td>78.37</td><td>152.43</td><td>222.14</td><td>287.47</td><td>348.38</td><td>404.84</td><td>378.43</td><td>351.8</td><td>324.95</td><td>297.88</td></tr></tbody></table>
