I have the below case in my report:
Receivable: RunningValue(Fields!Receivable.Value,SUM,Nothing)
Production: code.SumLookup(LookupSet(Fields!Currency_Type.Value, Fields!Currency_Type1.Value,Fields!Gross_Premium_Amount.Value, "DataSet2"))
Rec/Prod: Receivable / Production.
Public Function SumLookup(ByVal items As Object()) As Decimal
If items Is Nothing Then
Return Nothing
End If
Dim suma As Decimal = New Decimal()
Dim ct as Integer = New Integer()
suma = 0
ct = 0
For Each item As Object In items
suma += Convert.ToDecimal(item)
ct += 1
Next
If (ct = 0) Then return 0 else return suma
End Function
The problem is for Rec/Prod, if prod = 0 i receive error.
Ive tried to put the below condition:
IIF(code.SumLookup(LookupSet(Fields!Currency_Type.Value, Fields!Currency_Type1.Value,Fields!Gross_Premium_Amount.Value, "DataSet2"))=0,0,RunningValue(Fields!Receivable.Value,SUM,Nothing)/(code.SumLookup(LookupSet(Fields!Currency_Type.Value, Fields!Currency_Type1.Value,Fields!Gross_Premium_Amount.Value, "DataSet2"))))
but since in the false condition i am recalling code.SumLookup in order to get the value in regetting 0 for production and consiquently i get error for Rec/Prod.
how can i call code.sumlookup on time only and save its value into a variable so i dont need to call it everytime i need to check the value.
or if there any other solution please advise.
I did try to add textbox into the report and setting it’s value to your Production expression. I named the textbox “Production” and i refer to that value using the syntax ReportItems!Production.Value, but it also gave the same error.
The solution i found is the below:
For the below function, report builder will evaluate all parts of the function. This means that even though your function takes into account “if prod=0” it still goes on to do the Rec/Prod evaluation and so errors. Please try this formula, the extra ‘IF’ allows the function to evaluate without error.