[]
        
(Showing Draft Content)

LAG

This function provides access to the value from a row at a given physical offset which is before the current row. If there is no such row, the default value is returned. It does not accept window frame definitions, such as FRAMEROWS and FRAMERANGE.

Syntax

LAG(value_function, [offset_value], [default_value])

Arguments

The function provides the following arguments.

Argument

Description

value_function

[required] The field name or formula.

[offset_value]

[optional] Row offset before the current, offset = 1.

[default_value]

[optional] default value, default = null

Example

// WINDOW(LAG([@city]), ORDERBY([sold]))

city      |    sold    |    lag
----------------------------------------------
Paris         100           null
Berlin        150           Paris
Rome          200           Berlin
Moscow        200           Rome      
London        300           Moscow

// WINDOW(LAG([@city], 2), ORDERBY([sold]))

city     |   sold    |     lag
----------------------------------------------
Paris        100           null
Berlin       150           null
Rome         200           Paris
Moscow       200           Berlin
London       300           Rome