How to get only positive values out of a table

Hello,

I have a table with positive and negative numbers. I only want to sum the positive values and ignore the negative ones. When I try to do it with a CASE formula that says only select values > 0 then I get this error: Operator implementation could not be found or wrong types. Operator ‘CASE’ is not compatible with cases of type DOUBLE and LONG

Can someone help me to solve this?

Thanks

Sasan

Hi Sasan,

you can do something like this:

SUM(CASE WHEN "table"."column">0 THEN "table"."column" ELSE NULL END)

Hope that helps!

David

Hi David,

that helps a lot. Thank you!

I had the same formula, but except for NULL I had 0. Can you explain why it does not work with the 0?

Best Wishes

Sasan

Hi Sasan,

I suggest your column is a Float column. If you write 0 in the ELSE, this is an Integer, which is different from the Float data type returned in the THEN. In a CASE WHEN, you always have to return the same data type for all the specified cases.
NULL works for every data type and is ignored by the SUM operator.
Instead of NULL, you can also write 0.0 in the ELSE, because 0.0 is a Float.

Best,
David

Thank you for the explanation! I get it now :slight_smile: