← last_value operator page · aggregate/last_value/analytic_ds/manual_ex_1
pandas ✅ · DuckDB ✅
last_value at data set level, over a window from one data point before to one after in the order of Id_3.
Last value, Example 1, output verbatim: "The operator returns the last value (in the value order) of the set of Data Points that belong to the same analytic window as the current Data Point".
the values of the latest year in the window: 1993 gets those of 1994, 1994 those of 1995, 1995 and 1996 those of 1996; at A, XX, 1994 that is 7 and 5, while the greatest Me_2 of the window is 9.
DS_r := last_value ( DS_1 over ( partition by Id_1, Id_2 order by Id_3 data points between 1 preceding and 1 following ) );
| Id_1 | Id_2 | Id_3 | Me_1 | Me_2 |
|---|---|---|---|---|
| A | XX | 1993 | 3 | 1 |
| A | XX | 1994 | 4 | 9 |
| A | XX | 1995 | 7 | 5 |
| A | XX | 1996 | 6 | 8 |
| A | YY | 1993 | 9 | 3 |
| A | YY | 1994 | 5 | 4 |
| A | YY | 1995 | 10 | 2 |
| A | YY | 1996 | 2 | 7 |
{
"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}
]
}
]
}
| Id_1 | Id_2 | Id_3 | Me_1 | Me_2 |
|---|---|---|---|---|
| A | XX | 1993 | 4 | 9 |
| A | XX | 1994 | 7 | 5 |
| A | XX | 1995 | 6 | 8 |
| A | XX | 1996 | 6 | 8 |
| A | YY | 1993 | 5 | 4 |
| A | YY | 1994 | 10 | 2 |
| A | YY | 1995 | 2 | 7 |
| A | YY | 1996 | 2 | 7 |
{
"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"}
]
}
]
}