The Lag function references a column and returns its values in offset positions, shifting the output up or down by a fixed number of rows.
The Lead function typically shifts values up, while the Lag function shifts values down. However, Sigma enables positive and negative offsets, allowing both functions to shift values in either direction.
Lag(value, [offset], [default])
- value (required) - the column of values to reference
- offset (optional) - the number of rows by which the output shifts the referenced values
- positive integers shift values down (below the reference)
- negative integers shift values up (above the reference)
- default (optional) - the value to return in the row that doesn't reference a column value (the last row in a positive offset or first row in a negative offset)
If the offset argument isn't specified, the output shifts values down one row. If the default argument isn't specified, the output returns "null."
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.
Lag([Attendance], 1)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.