Rank · rank
---
config:
flowchart:
useMaxWidth: false
---
flowchart LR
classDef ok fill:#d4edda,stroke:#28a745,color:#000
classDef partial fill:#fff3cd,stroke:#ffc107,color:#000
classDef refused fill:#d4edda,stroke:#28a745,stroke-width:3px,stroke-dasharray: 2 2,color:#000
classDef missing fill:#f8d7da,stroke:#dc3545,color:#000
classDef diverge fill:#cce5ff,stroke:#007bff,color:#000
classDef block fill:#2b3a4a,stroke:#2b3a4a,color:#fff,font-weight:bold
classDef ext fill:#fff,stroke:#666,color:#000,stroke-dasharray: 5 5
O["Rank · rank<br/>🟢2"]:::ok
v_partition_order["DS#91;calc Me #58;#61; rank(over (partition by Id order by Me))#93;"]:::ok
v_order_only["DS#91;calc Me #58;#61; rank(over (order by Id))#93;"]:::ok
subgraph G_use["Used with"]
direction LR
used__clause__calc["calc ↗<br/><small>used in over()</small>"]:::ext
end
v_partition_order --- O
v_order_only --- O
O -.- G_use
style G_use fill:#ffffff,stroke:#868e96,stroke-width:1px,stroke-dasharray: 1 4
click v_partition_order href "#form-partition-order"
click v_order_only href "#form-order-only"
click used__clause__calc href "../clause/calc.html" "Calculation of a Component · calc"
Types
Takes any scalar · Gives integer
Comes from: any operator that returns a value
Goes to · integer — 44 operators in 8 blocks 🟢44
General purpose operators (1) 🟢1
String operators (2) 🟢2
Numeric operators (18) 🟢18
Time operators (6) 🟢6
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (10) 🟢10
Data validation operators (2) 🟢2
Definitions (VTL-DL) (4) 🟢4
Goes to · operators that take any scalar — 45 operators in 8 blocks 🟢45
General purpose operators (6) 🟢6
Join operators (4) 🟢4
Comparison operators (11) 🟢11
Set operators (4) 🟢4
Aggregate and Analytic operators (7) 🟢7
Data validation operators (1) 🟢1
Conditional operators (3) 🟢3
Forms
DS[calc Me := rank(over (partition by Id order by Me))] 🟢 · any scalar → integer
Manual example 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
rankincalc, partitioned byId_1andId_2and ordered byMe_1, with a tie.- Manual:
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”.
- Expected:
in
XX, 3, 4, 6 and 7 rank 1 to 4; inYY, 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 |
| 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 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
DS[calc Me := rank(over (order by Id))] 🟢 · any scalar → integer
Default partition by other identifiers 🟢 pandas ✅ · DuckDB ✅
- Tests:
rankwith an order clause and no partition clause.- Manual:
Analytic invocation: “If the clause is omitted, then the Data Set is partitioned by the Identifier Components that are not specified in the orderClause”; the order names
Id_2only, so the partition is byId_1.- Expected:
1 to 4 for the quarters of
A, 1 and 2 for those ofB; ranking the whole data set, as SQL does withoutPARTITION BY, would give 1, 3, 5, 6, 1, 3.
DS_r := DS_1 [ calc Me_3 := rank ( over ( order by Id_2 ) ) ];
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 |
| A | 2020Q2 | 1 | 3.500000 |
| A | 2021Q1 | 5 | 2.500000 |
| A | 2021Q2 | 1 | 0.500000 |
| B | 2020Q1 | 4 | 6.500000 |
| B | 2020Q2 | 8 | 4.500000 |
| Id_1 | Id_2 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|---|
| A | 2020Q1 | 3 | 1.500000 | 1 |
| A | 2020Q2 | 1 | 3.500000 | 2 |
| A | 2021Q1 | 5 | 2.500000 | 3 |
| A | 2021Q2 | 1 | 0.500000 | 4 |
| B | 2020Q1 | 4 | 6.500000 | 1 |
| B | 2020Q2 | 8 | 4.500000 | 2 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗