Q:

Modify Avg lookupset in SSRS to remove null

I have the follow custom function that I am using in an SSRS report in order to calculate an average value using the LookUpSet function. I have a number of results in the set that are returned that are null. At the moment this function is taking these as 0 and increasing the count. How would I modify this to exclude the 0 values so that it just skips them and keeps the count the same. ie. just excludes them completely from the dataset that is returned?
Function AvgLookup(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()
Dim Avg as Decimal = New Decimal()

suma = 0
ct = 0

For Each item As Object In items
suma += Convert.ToDecimal(item)
ct += 1
Next

Avg = suma / ct

If (ct = 0) Then return 0 else return Avg

End Function 

A:

It seems the easiest way would be to add a IF statement in your loop. This assumes it is converting the NULLS to 0 and you have no 0 values you want.
For Each item As Object In items
     IF Convert.ToDecimal(item) <> 0
        suma += Convert.ToDecimal(item)
        ct += 1
     ENDIF
Next

