← lag operator page · aggregate/lag/ds_offset/manual_ex_1

Manual example 1 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

lag with offset 1 at data set level, partitioned by Id_1 and Id_2 and ordered by Id_3.

Manual:

Lag, Example 1, output verbatim: "If defaultValue is not specified then the value returned when the offset goes outside the partition is null".

Expected:

each data point gets the values of the year before; 1993, the first of each partition, gets null.

script.vtl ⇩

DS_r := lag ( DS_1 , 1 over ( partition by Id_1 , Id_2 order by Id_3 ) );

input/DS_1.csv ⇩

Id_1Id_2Id_3Me_1Me_2
AXX199331
AXX199449
AXX199575
AXX199668
AYY199393
AYY199454
AYY1995102
AYY199627

input/DS_1.json ⇩

{
  "datasets": [
    {
      "name": "DS_1",
      "DataStructure": [
        {"name": "Id_1", "type": "String", "role": "Identifier", "nullable": false},
        {"name": "Id_2", "type": "String", "role": "Identifier", "nullable": false},
        {"name": "Id_3", "type": "Time_Period", "role": "Identifier", "nullable": false},
        {"name": "Me_1", "type": "Integer", "role": "Measure", "nullable": true},
        {"name": "Me_2", "type": "Integer", "role": "Measure", "nullable": true}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Id_2Id_3Me_1Me_2
AXX1993
AXX199431
AXX199549
AXX199675
AYY1993
AYY199493
AYY199554
AYY1996102

expected/DS_r.json ⇩

{
  "datasets": [
    {
      "name": "DS_r",
      "DataStructure": [
        {"name": "Id_1", "type": "String", "role": "Identifier"},
        {"name": "Id_2", "type": "String", "role": "Identifier"},
        {"name": "Id_3", "type": "Time_Period", "role": "Identifier"},
        {"name": "Me_1", "type": "Integer", "role": "Measure"},
        {"name": "Me_2", "type": "Integer", "role": "Measure"}
      ]
    }
  ]
}