I’m calculating a conditional sum that looks like this:

type: sum

sql:

CASE WHEN ${typ} = 0

THEN ${x} * -1

WHEN ${typ} = 1

THEN ${x} * -1

WHEN ${typ} = 2

THEN (${A} + ${B} + ${C} + ${D}) * -1

WHEN ${typ} = 6

THEN ${y} * -1

WHEN ${typ} = 7

THEN ${y} * -1

END ;;

I’m focused on typ [type] 2. When I compute this sum for a particular row, A B C are all null, and D has a value. The output of this is 0 and I don’t understand why. If I change the formula to just D, then D will populate, however when I compute (A + B + C + D) * -1, the output is 0. I tried wrapping A B C in nullif statements but the result is still 0. A B C aren’t even null, they are 0 in the data so that shouldn’t matter.

Why would this be? Why is D being ignored and the sum is just 0?

Thank you!