> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://help.sigmacomputing.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://help.sigmacomputing.com/_mcp/server.

# 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](/docs/lead) function shifts values up.

## Syntax

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

These are the function arguments:

<dl>
  <dt>
    value
  </dt>

  <dd>
    Required
  </dd>

  <dd>
    The column of values that the function shifts
  </dd>

  <dt id="offset">
    offset
  </dt>

  <dd>
    Optional
  </dd>

  <dd>
    The number of rows that the output shifts
  </dd>

  <dd>
    This number must be constant (the same) for all rows
  </dd>

  <dd>
    Must be an integer greater than 

    <code>0</code>
  </dd>

  <dd>
    Default, if omitted, is 

    <code>1</code>
  </dd>

  <dt id="default">
    default
  </dt>

  <dd>
    Optional
  </dd>

  <dd>
    The value to return in the row(s) at the end of the table, which don't have a valid offset index
  </dd>

  <dd>
    Default, if omitted, is 

    <code>Null</code>
  </dd>
</dl>

## Examples

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

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

In these examples, column **Lag** shows the [offset](/docs/lag#offset) lag as the default of 1 row and the [default](/docs/lag) is null, while column Lag 2 shows the [offset](/docs/lag#offset) lag as 2 rows and the [default](/docs/lag#default) is null.

![Default options for the Lag function](https://files.buildwithfern.com/sigma.docs.buildwithfern.com/ed3af1ec4dbf3ed7f8d0d615160217acc9a5ea8dd96ff512219258b48dd266b9/assets/docs-images/885e5fb-t1.png)

```
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.

![](https://files.buildwithfern.com/sigma.docs.buildwithfern.com/14243357a79620dad6f56569cf9441c5a2c4aa880f8027d460bff1a9f7b33218/assets/docs-images/f784d6a-t2.png)

## Related resources

* [Lead](/docs/lead)