Reputation: 95
My table contains 2 columns with numbers:
ORIGINAL_QTY FINAL_QTY
120 115
1 0
1 1
0 0
3 1
4 5
And I need to extract the diference between both numbers as a percentage, so I created the following expresion, taking into account increase o decrease in final quantity (swaping numerator and denominator) or 0 in denominator (changing 0 with 0.00001 will do the job because I round to 2 decimals):
=IIf(Fields!ORIGINAL_QTY.Value=0, (Fields!FINAL_QTY.Value/0.00001)*100, IIf(Fields!ORIGINAL_QTY.Value>=Fields!FINAL_QTY.Value, (Fields!FINAL_QTY.Value/Fields!ORIGINAL_QTY.Value)*100, (Fields!ORIGINAL_QTY.Value/Fields!FINAL_QTY.Value)*100))
But still throws me "error: divided by zero" on rows 2 and 4:
Row 2: Its just 0/1=0, nothing special, shouldn't throw error. Row 4: ORIGINAL_QTY = 0, but I took care of it in the expresion so...
What am I missing? Checked everything and it should work...
Upvotes: 0
Views: 97
Reputation: 2951
Alternatively, you could use the following custom code in your report and then call it in your report (right click report, report Properties - > Code
Public Shared Function VarPercent(ByVal Standard As Decimal, ByVal Actual As Decimal) As Decimal
If Actual = 0 Then
Return 0
End If
If Standard = 0 Then
Return 0
End If
Return (Standard / Actual )
End Function
Then you can call it like this in your report (where ever you are dividing)
Code.VarPercent (Fields!numerator.Value, Fields!denominator.Value)
Upvotes: 2