← case operator page · conditional/case/comp_multi_when/manual_ex_1

Manual example 1 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

case with three when clauses inside calc, returning scalars, on a measure that has a null.

Manual:

Case, Example 1, output verbatim: "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_2 is 0, 1, 10 and 100: each non-null Me_1 meets one condition, and the null meets none, as a comparison with null is not true, so the else gives 100. The three conditions exclude each other, so this example cannot tell the first true when from the last: "Overlapping descending thresholds" does.

script.vtl ⇩

DS_r := DS_1
   [calc Me_2 := 
         case when Me_1 <= 1 then 0
				      when Me_1 > 1 and Me_1 <= 10 then 1							
              when Me_1 > 10  then 10
              else 100];

input/DS_1.csv ⇩

Id_1Me_1
10.12
23.5
310.7
4

input/DS_1.json ⇩

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

expected/DS_r.csv ⇩

Id_1Me_1Me_2
10.120
23.51
310.710
4100

expected/DS_r.json ⇩

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