# Lag

The **Lag** function accesses data in preceding rows in the same result set, without having to join the table to itself. It references a column and returns its values in the offset position, shifting the output down by a fixed number of rows.

The **Lag** function typically shifts values down, while the [lead](https://support.meetuma.ai/uma-knowledgebase/data-and-reporting/analytics-pro/functions/window-functions/lead "mention") function shifts values up.

### Syntax

```
Lag(value, offset, default)
```

These are the function arguments:

<table><thead><tr><th width="258"></th><th></th></tr></thead><tbody><tr><td>value</td><td>Required<br>The column of values that the function shifts.</td></tr><tr><td>offset</td><td><p>Optional</p><p>The number of rows that the output shifts. This number must be constant (the same) for all rows. Must be an integer greater than <code>0</code>Default, if omitted, is <code>1</code></p></td></tr><tr><td>default</td><td><p>Optional </p><p>The value to return in the row(s) at the end of the table, which don't have a valid offset index. Default, if omitted, is <code>Null</code></p></td></tr></tbody></table>

###

### Examples

```
Lag([Year of Date])
```

In these examples, column **Lag** shows the offset lag as the default of 1 row and the default is null, while column Lag 2 shows the offset lag as 2 rows and the default is null.

<figure><img src="https://files.readme.io/885e5fb-t1.png" alt=""><figcaption></figcaption></figure>

```
Lag([Attendance], 1)
```

A table lists the total attendance for each game of an MLB team's 2021 season. You can use the **Lag** function to compare this value with the number of attendees recorded for the previous game.

The formula references the *Attendance* column and shifts its values down one row. The resulting output in each row of the *Previous Game* column indicates the number of people who attended the game that occurred immediately before the one referenced in the *Game Key* column.

<figure><img src="https://files.readme.io/f784d6a-t2.png" alt=""><figcaption></figcaption></figure>
