SSRS分组项目汇总(中位数,平均值)

时间:2015-04-01 19:05:26

标签: ssrs-2008

了解如何让我的报告看起来如下所示。关于Median函数,任何建议都会非常有用。在总计中,中间和平均值在基础结构中计算,而不是从上面计算的值计算。我应该注意到,我可以毫无疑问地获得平均值,这只是中位数。

我按商店分组,然后按商品分组。

Store 1
Item          QTY          Median          Average        
Apples         17            31              33            
Oranges       182            17              21 
Totals        199            25              24


Store 2
Etc.

我在这个博客上发现了一篇非常好的文章,但我无法让它与这个分组合作。 Blog Link

我想使用的代码看起来像这样。

现在的问题是如何正确使用它?

我尝试在项目组中添加变量。 = Code.AddValue(领域!myValue.Value) 然后在我添加的细胞领域 = Code.GetMedian()

它返回垃圾结果。

Dim values As New System.Collections.Generic.List(Of Integer)
Dim valueCounts As New System.Collections.Generic.Dictionary(Of Integer, Integer)

Function AddValue(newValue As Integer) As Integer
    values.Add(newValue)
    AddValue = newValue
    If Not valueCounts.ContainsKey(newValue) Then
        valueCounts.item(newValue) = 1
    Else
        valueCounts.item(newValue) += 1
    End If
End Function

Function GetMedian() As Double
    Dim count As Integer = values.Count
    If count = 0 Then
        Return 0
    Else
        values.Sort()
        If count Mod 2 = 1 Then
            Return values(CInt((count / 2) - 0.5))
        Else
            Dim index1 As Integer = count \ 2
            Dim index2 As Integer = index1 - 1

            Dim value1, value2 As Integer
            value1 = values(index1)
            value2 = values(index2)

            Return (value1 + value2) / 2
        End If
    End If

End Function

0 个答案:

没有答案
相关问题