LAG returns a value from a preceding position within the specified dimension. 

You could use LAG to calculate how this month's earnings compare to last year's monthly earnings. 

LAG(Value to offset, Offset amount, Substitute value [, Non-positive behavior, List])

ArgumentData TypeDescription
Value to offsetNumber, Boolean, date,
time period, list, or text

Value to replace with a value from a different time period.

See the Calculation engine functionality differences section for the use of a non-numeric argument in the Classic engine.

Offset amountNumber

Number of positions to move from the current reference value:

  • Positive values move forward through the dimension.
  • Negative values move backward through the dimension.
  • Zero stays at the current position.
Substitute valueSame as Value to offset

Value to return if the Offset amount specifies a position outside or beyond the current reference value.

Also used for non-positive offsets if you use the SEMISTRICT or STRICT keywords for the Non-positive behavior argument.

Non-positive behavior (optional) KeywordDetermines how the LAG function uses the Substitute value argument.
List (Polaris only)List

The list over which the function should operate. The target line item must be dimensioned with any dimension compatible with this list. 

You must provide a Non-positive behavior keyword to use LAG on a list.

See Calculation engine functionality differences.

The LAG function returns a result of the same data type as the Value to offset argument.

The List argument is optional. If you omit it, the function defaults to the Time dimension. If you include it, you can use any dimension that is compatible with the line item.

KeywordDescription
NONSTRICT

The default keyword if you omit the Non-positive behavior argument.

Returns the Value to offset if the Offset amount is positive, negative, or zero.

SEMISTRICTReturns the Value to offset if the Offset amount is positive or zero. 
STRICTReturns the Value to offset if the Offset amount is positive.

In Polaris:

  • Any number used for the Offset amount argument is rounded to the nearest integer. A value of NaN (Not a Number) for the Offset amount argument returns the Substitute value argument.
  • You can use LAG with any dimension except Versions. In the Classic Engine, you can use this function only with a time dimension.

In the Classic Engine:

  • You can use non-numeric Value to offset arguments, but only when the Offset amount is a constant. Otherwise, an error message displays.
  • Any number used for the Offset amount argument is rounded toward zero. A value of NaN is equivalent to 0.

LAG(Value to offset, 2, 0)


JanFebMarAprMayJun
Value to offset3,0001,0002,0007,0002,5003,000
LAG 1003,0001,0002,0007,000

In this example, the LAG 1 line item contains the formula above. This means it returns the value from two periods before.

Since for Jan and Feb, two periods before the cells are outside of the module’s time range, the formula returns the Substitute value of 0. The function does not contain the Non-positive behavior argument, so the default behavior is NONSTRICT.

If the period LAG specifies is outside of the module's time range, LAG returns the value of the substitute value argument.

In this example, the Lag by two periods line item contains a formula that returns the Value to offset from two periods prior.


JanFebMarAprMayJun
Value to offset3,0001,0002,0007,0002,5003,000
Substitute value1016125
Lag by two periods
LAG(Value to offset, 2, Substitute value)
1013,0001,0002,0007,000

When the Offset amount specifies a period that falls outside the time range, LAG returns the Substitute value amount, as shown in Jan and Feb columns.

The formula does not contain the Non-positive behavior argument, so it uses the default behavior, NONSTRICT.

In this example, the LAG with constant offset line item contains the formula above. This means it returns line item from two periods before each cell.

If the Substitute value amount falls outside the model time range, the value from the Value to offset row in the current period is used, as shown in Jan and Feb columns. The formula does not contain the Non-positive behavior argument, so it uses the default behavior, NONSTRICT.


JanFebMarAprMayJun
Value to offset3,0001,0002,0007,0002,5003,000
Substitute value1016125
LAG with constant offset
LAG(Value to offset, 2, Substitute value)
1013,0001,0002,0007,000

In this example, you can see how the different keywords for the Non-positive behavior argument change the results.


JanFebMarAprMayJun
Value to offset123456
Offset amount0-10101
Substitute value100200300400500600
Semistrict behavior
LAG(Value to offset, Offset amount, Substitute value, SEMISTRICT)
12003355
Strict behavior
LAG(Value to offset, Offset amount, Substitute value, STRICT)
10020030035005
Nonstrict behavior
LAG(Value to offset, Offset amount, Substitute value, NONSTRICT)
133355