Hi everyone, is it possible to do a % change by ye...
# general
d
Hi everyone, is it possible to do a % change by year in a saved search formula? I get the ERROR: Possible Divide by Zero error on my final formula: Is this possible via Saved search?
((CASE WHEN TO_CHAR({transaction.trandate}, 'YYYY') = '2023' THEN {transaction.amount} ELSE 0 END ) - (CASE WHEN TO_CHAR({transaction.trandate}, 'YYYY') = '2024' THEN {transaction.amount} ELSE 0 END) ) / CASE WHEN TO_CHAR({transaction.trandate}, 'YYYY') = '2023' THEN {transaction.amount} ELSE 0 END
If I change the "ELSE 0" to "ELSE 1" I get the "Unexpected error has occurred" screen
t
You can't divide by a possible value of 0
d
Thanks tim, if I replace the end of the denominator statement with ELSE 1 I get the unexpected error has occured screen
m
((CASE WHEN TO_CHAR({trandate}, 'YYYY') = '2023' THEN {amount} ELSE 0 END) - (CASE WHEN TO_CHAR({trandate}, 'YYYY') = '2024' THEN {amount} ELSE 0 END)) / NULLIF((CASE WHEN TO_CHAR({trandate}, 'YYYY') = '2023' THEN {amount} ELSE 0 END), 0)
t
If that doesn't work then
(CASE WHEN TO_CHAR({trandate}, 'YYYY') = '2023' THEN {amount} ELSE 0 END - CASE WHEN TO_CHAR({trandate}, 'YYYY') = '2024' THEN {amount} ELSE 0 END) / NULLIF(CASE WHEN TO_CHAR({trandate}, 'YYYY') = '2023' THEN {amount} ELSE 0 END, 0)
s
d
thanks for your help everyone!