简体   繁体   English

在SSRS中修改Avg lookupset以删除null

[英]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. 我具有在SSRS报表中使用的Follow自定义函数,以便使用LookUpSet函数计算平均值。 I have a number of results in the set that are returned that are null. 我在返回的结果集中有许多结果为null。 At the moment this function is taking these as 0 and increasing the count. 目前,此功能将这些值设为0并增加计数。 How would I modify this to exclude the 0 values so that it just skips them and keeps the count the same. 我将如何修改它以排除0值,以便它跳过它们并保持计数不变。 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 

It seems the easiest way would be to add a IF statement in your loop. 似乎最简单的方法是在循环中添加IF语句。 This assumes it is converting the NULLS to 0 and you have no 0 values you want. 假设它正在将NULLS转换为0,并且您没有想要的0值。

For Each item As Object In items
     IF Convert.ToDecimal(item) <> 0
        suma += Convert.ToDecimal(item)
        ct += 1
     ENDIF
Next

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM