I'm trying to define a formula column that implements logic like this case statement would:
- case
- when numfld1 is null then null
- when numfld2 > 0 then 100*numfld2
- when numfld2 < 0 then numfld2
- else 0.0
- end
In formula columns, the docs say you need to use if_case for this sort of logic. I have no idea how to do the > 0 comparison in if_case. The dumb way if_case separates the column name from the test doesn't help. From the examples given for if_case, I would guess somehing like this:
if_case('numfld1', null, null, 'numfld2', gt(0), "numfld2"*100, 'numfld2', lt(0), "numfld2", 0.0)
That doesn't work though, because there are no formula functions like gt() and lt() as far as I can tell. Even the equals() mentioned in the documentation doesn't seem to work right.
So, what is the proper translation of this logic into an if_case formula? And where can documentation about it be found?
And, while on the topic, why does if_case not work like the if function does. Like, wouldn't if_case be better if its arguments worked the way the if() function's do? Something like:
if_case("numfld1" is null, null, "numfld2'" > 0, "numfld2"*100, "numfld2" < 0, "numfld2", 0.0)
Why doesn't if() just do that in the first place?