← rank operator page · aggregate/rank/partition_order/manual_ex_1
pandas ✅ · DuckDB ✅
rank in calc, partitioned by Id_1 and Id_2 and ordered by Me_1, with a tie.
Rank, Example 1, output verbatim: "If some Data Points are in the same order according to the specified orderClause, the same order number (rank) is assigned and a gap appears in the sequence of the assigned ranks".
in XX, 3, 4, 6 and 7 rank 1 to 4; in YY, the two 5s rank 1, then 9 ranks 3 and 10 ranks 4.
DS_r := DS_1 [ calc Me_2 := rank ( over ( partition by Id_1 , Id_2 order by Me_1 ) ) ];
| Id_1 | Id_2 | Id_3 | Me_1 | Me_2 |
|---|---|---|---|---|
| A | XX | 2000 | 3 | 1 |
| A | XX | 2001 | 4 | 9 |
| A | XX | 2002 | 7 | 5 |
| A | XX | 2003 | 6 | 8 |
| A | YY | 2000 | 9 | 3 |
| A | YY | 2001 | 5 | 4 |
| A | YY | 2002 | 10 | 2 |
| A | YY | 2003 | 5 | 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 | 2000 | 3 | 1 |
| A | XX | 2001 | 4 | 2 |
| A | XX | 2002 | 7 | 4 |
| A | XX | 2003 | 6 | 3 |
| A | YY | 2000 | 9 | 3 |
| A | YY | 2001 | 5 | 1 |
| A | YY | 2002 | 10 | 4 |
| A | YY | 2003 | 5 | 1 |
{
"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"}
]
}
]
}