0
votes

So I want to calculate the difference of last month and this month usage of data in my report. Both are decimal. I have this expression in my report

IIf(Fields!LastMonth.Value=0, ((Fields!ThisMonth.Value-Fields!LastMonth.Value)*100), Floor(((Fields!ThisMonth.Value-Fields!LastMonth.Value)/Fields!LastMonth.Value)*100)) * " %"

this statement keep returning #Error and I try to simplify the statement to

IIf(Fields!LastMonth.Value=0, "0","NOT 0")

and it returns 0 right, which means that it falls to right condition.

I guess the statement Floor(((Fields!ThisMonth.Value-Fields!LastMonth.Value)/Fields!LastMonth.Value)*100) causing the error, because divide-by-zero error encountered.

What I don't understand is, I state the condition if lastMonth.value is 0 it will fall to the first condition, which is no divide-by-zero condition could be caused. Why the second condition affect the whole statement causing error? I thought that the second statement won't be reached because it will fall to the first condition, right?

Can anybody explain it? Or is there any best way to avoid this divide-by-zero condition?

Best regards.

2
where is the solution ?rodrigo.rodriguez
my problen is =Fields!Saldo.Value*100/Fields!CostoNeto.Valuerodrigo.rodriguez

2 Answers

1
votes
IIf(Fields!LastMonth.Value=0, (( CInt(Fields!ThisMonth.Value)- 
CInt(Fields!LastMonth.Value))*100), Floor(((CInt(Fields!ThisMonth.Value)- 
CInt(Fields!LastMonth.Value))/ CInt(Fields!LastMonth.Value))*100)))
0
votes

IIF evaluates all arguments. If any argument generates an error, then the entire function will throw an error, regardless of which of the three arguments should have been returned.

Quoted from this answer.