← first_value operator page · aggregate/first_value/analytic_ds/manual_ex_1
pandas ✅ · DuckDB ✅
first_value at data set level, over a window from one data point before to one after in the order of Id_3.
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".
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.
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));
| 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 | 3 | 1 |
| A | XX | 1994 | 3 | 1 |
| A | XX | 1995 | 4 | 9 |
| A | XX | 1996 | 7 | 5 |
| A | YY | 1993 | 9 | 3 |
| A | YY | 1994 | 9 | 3 |
| A | YY | 1995 | 5 | 4 |
| A | YY | 1996 | 10 | 2 |
{
"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"}
]
}
]
}