← case operator page · conditional/case/comp/smaller_of_two_components

Smaller of two components 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

case when Me_1 < Me_2 then Me_1 else Me_2 inside calc: one when with component branches, so the conditions cannot overlap.

Manual:

Case: at Component level "the operation is applied for each Data Point of the unique input Data Set, the case operator returns the value from the thenOperand Component whose corresponding condition evaluates to true; if none of the when conditions evaluates to true, it returns the value from the elseOperand Component".

Expected:

Me_3 is the smaller measure: 5, 3 and 7. Me_1 < Me_2 is true only for 3 < 8; for 10 and 5, and for 7 and 7, the else gives Me_2.

script.vtl ⇩

DS_r := DS_1[calc Me_3 := case when Me_1 < Me_2 then Me_1 else Me_2];

input/DS_1.csv ⇩

Id_1Me_1Me_2
1105
238
377

input/DS_1.json ⇩

{
  "datasets": [
    {
      "name": "DS_1",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
        {"name": "Me_1", "type": "Integer", "role": "Measure", "nullable": true},
        {"name": "Me_2", "type": "Integer", "role": "Measure", "nullable": true}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Me_1Me_2Me_3
11055
2383
3777

expected/DS_r.json ⇩

{
  "datasets": [
    {
      "name": "DS_r",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier"},
        {"name": "Me_1", "type": "Integer", "role": "Measure"},
        {"name": "Me_2", "type": "Integer", "role": "Measure"},
        {"name": "Me_3", "type": "Integer", "role": "Measure"}
      ]
    }
  ]
}