← case operator page · conditional/case/comp_multi_when/manual_ex_1
pandas ✅ · DuckDB ✅
case with three when clauses inside calc, returning scalars, on a measure that has a null.
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".
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.
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];
| Id_1 | Me_1 |
|---|---|
| 1 | 0.12 |
| 2 | 3.5 |
| 3 | 10.7 |
| 4 |
{
"datasets": [
{
"name": "DS_1",
"DataStructure": [
{"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
{"name": "Me_1", "type": "Number", "role": "Measure", "nullable": true}
]
}
]
}
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 0.12 | 0 |
| 2 | 3.5 | 1 |
| 3 | 10.7 | 10 |
| 4 | 100 |
{
"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"}
]
}
]
}