Page 1 of 1

Divide by Zero exception with Formula

Posted: Wed Mar 25, 2009 8:31 pm
by ryanlio
Hi,
I'm using a text field for calculation. Somehow I'm receiving a divide by zero exception
As a test, this works fine:
{IIF(DS_Forecast.DS_SG35_Forecast.MN_CgAvail== 0,0,(1)/DS_Forecast.DS_SG35_Forecast.MN_CgAvail )}

However, when i subsitute (1) with (Sum(Data1,DS_Forecast.DS_SG35_Forecast.FG_Inv)) into
{IIF(DS_Forecast.DS_SG35_Forecast.MN_CgAvail== 0,0,(Sum(Data1,DS_Forecast.DS_SG35_Forecast.FG_Inv))/DS_Forecast.DS_SG35_Forecast.MN_CgAvail )}
It throws a "Divide by zero exception


Please advise on any workarounds

Also, I will expect the calculation not to happen at all since the divisor is a 0, it should just return a 0. yes?


Divide by Zero exception with Formula

Posted: Wed Mar 25, 2009 9:06 pm
by ryanlio
Sorted out.
"Expressions with condition"

Used this instead
{DS_Forecast.DS_SG35_Forecast.MN_CgAvail== 0 ? 0 : Sum(Data1,DS_Forecast.DS_SG35_Forecast.FG_Inv)* DS_Forecast.DS_SG35_Forecast.Total_Val /DS_Forecast.DS_SG35_Forecast.MN_CgAvail}

This works