Maximum value · max

🟢 8 of 8 forms all ok · VTL 2.2 Reference Manual ↗ · vtlengine 1.10.0rc3 (9e1c81a6) · pandas 2.3.3 · DuckDB 1.5.5
🟢 all ok🟡 partially implemented🛡️ refused with an error🔴 not implemented or crash🔵 engines differ ✅ match · ❌ wrong result · 🛡 guarded error (code) · 💥 crash · 📌 team decision
Dataset formsComponent formsScalar forms
        ---
config:
  flowchart:
    useMaxWidth: false

---
flowchart TB
    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["Maximum value · max<br/>🟢8"]:::ok
    subgraph G_ds["Dataset"]
        direction LR
        v_ds_no_group["max(DS)"]:::ok
        v_ds_group_by["max(DS group by Id)"]:::ok
        v_ds_group_except["max(DS group except Id)"]:::ok
        v_ds_group_all["max(DS group all time_agg(#quot;A#quot;))"]:::ok
        v_ds_having["max(DS group by Id having cond)"]:::ok
        v_analytic_ds["max(DS over (partition by Id))"]:::ok
    end
    subgraph G_comp["Component"]
        direction LR
        v_comp_in_aggr["DS#91;aggr Me #58;#61; max(Me) group by Id#93;"]:::ok
        v_analytic_comp["DS#91;calc Me #58;#61; max(Me over (partition by Id))#93;"]:::ok
    end
    subgraph G_use["Used with"]
        direction LR
        used__clause__aggr["aggr ↗<br/><small>used in</small>"]:::ext
        used__clause__calc["calc ↗<br/><small>used in over()</small>"]:::ext
    end
    O --- G_ds
    O --- G_comp
    O -.- G_use
    style G_ds fill:#f8f9fa,stroke:#495057,stroke-width:2px
    style G_comp fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 8 5
    style G_use fill:#ffffff,stroke:#868e96,stroke-width:1px,stroke-dasharray: 1 4
    click v_ds_no_group href "#form-ds-no-group"
    click v_ds_group_by href "#form-ds-group-by"
    click v_ds_group_except href "#form-ds-group-except"
    click v_ds_group_all href "#form-ds-group-all"
    click v_ds_having href "#form-ds-having"
    click v_comp_in_aggr href "#form-comp-in-aggr"
    click v_analytic_ds href "#form-analytic-ds"
    click v_analytic_comp href "#form-analytic-comp"
    click used__clause__aggr href "../clause/aggr.html" "Aggregation · aggr"
    click used__clause__calc href "../clause/calc.html" "Calculation of a Component · calc"
    

Types

Takes boolean, any scalar · Gives any type

Viral attributes: combined with the propagation rules → Viral propagation

Comes from: any operator that returns a value

Goes to: whatever takes its input's type

Forms

max(DS) 🟢 · any scalar → any type

Single group no identifiers 🟢 pandas ✅ · DuckDB ✅
Tests:

max with no grouping clause, over the shared input with two Number measures and no null.

Manual:

Aggregate invocation: “If the grouping clause is omitted, then all the input Data Points are aggregated in a single group and the clause returns a Data Set that contains a single Data Point and has no Identifiers.”

Expected:

one data point with no identifiers: Me_1 = 8 and Me_2 = 6.5, the greatest values.

script.vtl
DS_r := max ( DS_1 );
Input DS_1
Id_1Id_2Me_1Me_2
A2020Q131.500000
A2020Q213.500000
A2021Q152.500000
A2021Q210.500000
B2020Q146.500000
B2020Q284.500000
Expected DS_r
Me_1Me_2
86.500000

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

max(DS group by Id) 🟢 · any scalar → any type

Manual example 1 🟢 pandas ✅ · DuckDB ✅
Tests:

max at data set level grouped by Id_1, over one Integer measure.

Manual:

Maximum value, Example 1, output verbatim: “The operator returns the maximum of the input values.”

Expected:

7 for 2011, the greatest of 3, 5 and 7, and 4 for 2012, of 2 and 4; Me_1 stays Integer.

script.vtl
DS_r := max ( DS_1 group by Id_1 );
Input DS_1
Id_1Id_2Id_3Me_1
2011AXX3
2011AYY5
2011BYY7
2012AXX2
2012BYY4
Expected DS_r
Id_1Me_1
20117
20124

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

String measure 🟢 pandas ✅ · DuckDB ✅
Tests:

max over a String measure, grouped by Id_1.

Manual:

Maximum value: “For other comparable scalar types (for example time, string, boolean), the result has the same type as the operand”.

Expected:

the greatest Strings, pear for A and plum for B; in A it is neither the first nor the last value in the order of Id_2. Strings compare character by character (the Greater than page gives false for "hello" > "hi"), and these words start with different letters: apple < fig < kiwi < pear and date < plum.

script.vtl
DS_r := max ( DS_1 group by Id_1 );
Input DS_1
Id_1Id_2Me_1
A2020Q1kiwi
A2020Q2apple
A2021Q1pear
A2021Q2fig
B2020Q1plum
B2020Q2date
Expected DS_r
Id_1Me_1
Apear
Bplum

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

max(DS group except Id) 🟢 · any scalar → any type

Drops the listed identifier 🟢 pandas ✅ · DuckDB ✅
Tests:

max with group except Id_2: the data points are grouped by Id_1, the identifier that it does not name.

Manual:

Aggregate invocation: “group except: the Data Points are grouped by the values of the Identifiers not specified as groupingId. The Identifiers specified as groupingId are dropped in the result.”

Expected:

Id_1 and the two measures, without Id_2: 5 and 3.5 for A, 8 and 6.5 for B, the greatest values.

script.vtl
DS_r := max ( DS_1 group except Id_2 );
Input DS_1
Id_1Id_2Me_1Me_2
A2020Q131.500000
A2020Q213.500000
A2021Q152.500000
A2021Q210.500000
B2020Q146.500000
B2020Q284.500000
Expected DS_r
Id_1Me_1Me_2
A53.500000
B86.500000

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

max(DS group all time_agg("A")) 🟢 · any scalar → any type

Quarters to years 🟢 pandas ✅ · DuckDB ✅
Tests:

max with the deprecated group all time_agg ( "A" ), which turns each quarter of Id_2 into its year, written 2020 or 2021.

Manual:

Aggregate invocation: “group all: converts the values of an Identifier Component using conversionExpr and keeps all the resulting Identifiers”; Time aggregation: “On time_period type, the operator maps the input value into the comprising larger time period specified by the periodIndTo parameter”.

Expected:

Id_1, the year and the two measures: 3 and 3.5 for A, 2020, 5 and 2.5 for A, 2021 and 8 and 6.5 for B, 2020.

script.vtl
DS_r := max ( DS_1 group all time_agg ( "A" ) );
Input DS_1
Id_1Id_2Me_1Me_2
A2020Q131.500000
A2020Q213.500000
A2021Q152.500000
A2021Q210.500000
B2020Q146.500000
B2020Q284.500000
Expected DS_r
Id_1Id_2Me_1Me_2
A202033.500000
A202152.500000
B202086.500000

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

max(DS group by Id having cond) 🟢 · any scalar, boolean → any type

Two measures 🟢 pandas ✅ · DuckDB ✅
Tests:

max with having, over the two measures of the shared input.

Manual:

Aggregate invocation: the havingCondition “must invoke aggregate operators”, and “only groups for which havingCondition evaluates to true appear in the result”. The condition aggregates Me_1 only, where the manual and the reading of #1119 agree.

Expected:

max ( Me_1 ) < 6 is 5 for A and 8 for B, so only A is kept, with 5 and 3.5.

script.vtl
DS_r := max ( DS_1 group by Id_1 having max ( Me_1 ) < 6 );
Input DS_1
Id_1Id_2Me_1Me_2
A2020Q131.500000
A2020Q213.500000
A2021Q152.500000
A2021Q210.500000
B2020Q146.500000
B2020Q284.500000
Expected DS_r
Id_1Me_1Me_2
A53.500000

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

One measure 🟢 pandas ✅ · DuckDB ✅
Tests:

max with the having of Two measures, on a single-measure operand: the shared input without Me_2.

Manual:

Aggregate invocation: “only groups for which havingCondition evaluates to true appear in the result”; the page does not restrict having to single-measure operands.

Expected:

max ( Me_1 ) < 6 holds for A only, which is kept with Me_1 = 5.

script.vtl
DS_r := max ( DS_1 group by Id_1 having max ( Me_1 ) < 6 );
Input DS_1
Id_1Id_2Me_1
A2020Q13
A2020Q21
A2021Q15
A2021Q21
B2020Q14
B2020Q28
Expected DS_r
Id_1Me_1
A5

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

max(DS over (partition by Id)) 🟢 · any scalar → any type

Whole partition without order 🟢 pandas ✅ · DuckDB ✅
Tests:

max as an analytic function at data set level, partitioned by Id_1, with no order and no window clause.

Manual:

Analytic invocation: “If windowClause is not specified, then the set of Data Points which contribute to the analytic operation is the whole partition which the current Data Point belongs to”. With no order clause, the two defaults that the page gives for an omitted window agree.

Expected:

every data point gets the values of its partition: 5 and 3.5 in A, 8 and 6.5 in B.

script.vtl
DS_r := max ( DS_1 over ( partition by Id_1 ) );
Input DS_1
Id_1Id_2Me_1Me_2
A2020Q131.500000
A2020Q213.500000
A2021Q152.500000
A2021Q210.500000
B2020Q146.500000
B2020Q284.500000
Expected DS_r
Id_1Id_2Me_1Me_2
A2020Q153.500000
A2020Q253.500000
A2021Q153.500000
A2021Q253.500000
B2020Q186.500000
B2020Q286.500000

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

DS[aggr Me := max(Me) group by Id] 🟢 · any scalar → any type

Keeps only calculated measure 🟢 pandas ✅ · DuckDB ✅
Tests:

max at component level in aggr, grouped by Id_1.

Manual:

Aggregate invocation: “For the invocation at Component level, the resulting Data Set has the Measures explicitly calculated (all the other Measures are dropped because no aggregation behaviour is specified for them).”

Expected:

Id_1 and Me_3 only: 5 for A and 8 for B, the greatest values.

script.vtl
DS_r := DS_1 [ aggr Me_3 := max ( Me_1 ) group by Id_1 ];
Input DS_1
Id_1Id_2Me_1Me_2
A2020Q131.500000
A2020Q213.500000
A2021Q152.500000
A2021Q210.500000
B2020Q146.500000
B2020Q284.500000
Expected DS_r
Id_1Me_3
A5
B8

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

DS[calc Me := max(Me over (partition by Id))] 🟢 · any scalar → any type

Whole partition without order 🟢 pandas ✅ · DuckDB ✅
Tests:

max as an analytic function in calc, partitioned by Id_1, with no order and no window clause.

Manual:

Analytic invocation: “the resulting Data Set retains all the original components of the input Data Set plus the components explicitly calculated by it”; with no order and no window clause, the window is the whole partition.

Expected:

the input, plus Me_3 = 5 on the data points of A and 8 on those of B.

script.vtl
DS_r := DS_1 [ calc Me_3 := max ( Me_1 over ( partition by Id_1 ) ) ];
Input DS_1
Id_1Id_2Me_1Me_2
A2020Q131.500000
A2020Q213.500000
A2021Q152.500000
A2021Q210.500000
B2020Q146.500000
B2020Q284.500000
Expected DS_r
Id_1Id_2Me_1Me_2Me_3
A2020Q131.5000005
A2020Q213.5000005
A2021Q152.5000005
A2021Q210.5000005
B2020Q146.5000008
B2020Q284.5000008

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗