← first_value operator page · aggregate/first_value/analytic_ds/manual_ex_1

Manual example 1 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

first_value at data set level, over a window from one data point before to one after in the order of Id_3.

Manual:

First value, Example 1, output verbatim: "The operator returns the first value (in the value order) of the set of Data Points that belong to the same analytic window as the current Data Point".

Expected:

the values of the earliest year in the window: 1993 and 1994 get those of 1993, 1995 those of 1994 and 1996 those of 1995; at A, XX, 1995 that is 4 and 9, while the smallest Me_2 of the window is 5.

script.vtl ⇩

DS_r := first_value ( DS_1 over ( partition by Id_1, Id_2 order by Id_3 data points between 1 preceding and 1 following));

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
AXX199331
AXX199431
AXX199549
AXX199675
AYY199393
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"}
      ]
    }
  ]
}