Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reporting services 计算SSRS中的百分位数_Reporting Services_Ssrs 2012_Reportbuilder3.0_Percentile - Fatal编程技术网

Reporting services 计算SSRS中的百分位数

Reporting services 计算SSRS中的百分位数,reporting-services,ssrs-2012,reportbuilder3.0,percentile,Reporting Services,Ssrs 2012,Reportbuilder3.0,Percentile,我们需要根据共享数据集计算SSRS报告中的百分位(第95位和第99位),共享数据集每隔15分钟返回聚合数据。百分位数需要是一天的整体,但根据合同 为了论证起见,假设这是我们的数据: select 'Test' as [ContractName], 1 as [Value] union all select 'Test' as [ContractName], 3 as [Value] union all select 'Test' as [Contr

我们需要根据共享数据集计算SSRS报告中的百分位(第95位和第99位),共享数据集每隔15分钟返回聚合数据。百分位数需要是一天的整体,但根据合同

为了论证起见,假设这是我们的数据:

select
    'Test' as [ContractName],
    1 as [Value]

union all

select
    'Test' as [ContractName],
    3 as [Value]

union all

select
    'Test' as [ContractName],
    4 as [Value]

union all

select
    'Test' as [ContractName],
    6 as [Value]

union all

select
    'Test' as [ContractName],
    7 as [Value]

union all

select
    'Test' as [ContractName],
    36 as [Value]

union all

select
    'Test' as [ContractName],
    56 as [Value]

union all

select
    'Test' as [ContractName],
    798 as [Value]

union all

select
    'Test' as [ContractName],
    324 as [Value]

union all

select
    'Test' as [ContractName],
    456 as [Value]

union all

select
    'Test' as [ContractName],
    657 as [Value]

union all

select
    'Test' as [ContractName],
    658 as [Value]
这几乎是分类的(我创建它时是这样),但数据本身不会出现在实际应用程序中

我需要能够在不改变SQL的情况下从该数据集获取百分比,因为它是用于合同报告的共享数据集,不能更改。共享数据集用于确保整个报告套件的一致性。因此,解决方案必须在最终报告输出的表格中


我已经看过并注意到它与此具有相同的基本用法,它来自并需要大量隐藏的行和组变量,这些变量在以后不容易维护/编辑。

可以将以下自定义代码添加到报告中:

Public Shared Function Centile(ByVal items As Object(), ByVal k As Decimal) As Decimal
    If items Is Nothing Then
        Return Nothing
    End If

    Dim counter as Decimal = items.Length
    If counter = 0 Then
        Return 0
    End If

    System.Array.Sort(items)

    Dim Position As Decimal = (k * (counter - 1))

    Dim FirstIndex As Integer = Floor(Position)
    Dim SecondIndex As Integer = Ceiling(Position)

    Dim Remainder As Decimal = Position - FirstIndex

    Dim FirstValue As Integer = items(FirstIndex)
    Dim SecondValue As Integer = items(SecondIndex)


    Return (FirstValue + (Remainder * (SecondValue - FirstValue)))

End Function
可以使用表达式中的
lookupset()
调用它,如下所示:

=Code.Centile(lookupset(Fields!ContractName.Value, Fields!ContractName.Value, Fields!Value.Value, "DS_Centile_LKP"), 0.95)
这将调用自身,通过查找ContractName字段从同一数据集获取值。
lookupper()
返回一个数组,在这个函数中进行排序,而不是到处都有变量和东西-这是tablix文本框中显示值的一个简单函数。 它还允许您使用不同的百分位值-在上面的示例中,它是第95位,因此为0.95