在SSAS中计算百分位值

在SSAS中计算百分位值,ssas,mdx,business-intelligence,olap-cube,percentile,Ssas,Mdx,Business Intelligence,Olap Cube,Percentile,我试图计算一个立方体中的百分位(例如,我度量的第90个百分位点),我想我差不多到了。我面临的问题是,我能够返回第90百分位的行数,但不知道如何获取我的度量值 With Member [Measures].[cnt] as Count(NonEmpty( -- dimensions to find percentile on (the same should be repeated again [Calendar].[Hierarchy].members * [Region Dim].[Reg

我试图计算一个立方体中的百分位(例如,我度量的第90个百分位点),我想我差不多到了。我面临的问题是,我能够返回第90百分位的行数,但不知道如何获取我的度量值

With
Member [Measures].[cnt] as 
Count(NonEmpty(
-- dimensions to find percentile on (the same should be repeated again
[Calendar].[Hierarchy].members * 
[Region Dim].[Region].members * 
[Product Dim].[Product].members
,
-- add the measure to group
[Measures].[Profit]))

-- define percentile
Member [Measures].[Percentile] as 90

Member [Measures].[PercentileInt] as Int((([Measures].[cnt]) * [Measures].[Percentile]) / 100)

**-- this part finds the tuple from the set based on the index of the percentile point and I am using the item(index) to get the necessary info from tuple and I am unable to get the measure part 
Member [Measures].[PercentileLo] as
(
Order(
NonEmpty(
    [Calendar].[Hierarchy].members * 
    [Region Dim].[Region].members * 
    [Product Dim].[Product].members,
    [Measures].[Profit]),
    [Measures].[Profit].Value, BDESC)).Item([Measures].[PercentileInt]).Item(3)**

select
{
[Measures].[cnt],
[Measures].[Percentile],[Measures].[PercentileInt],
[Measures].[PercentileLo],
[Measures].[Profit]
}
on 0
from
[TestData]

我认为一定有一种方法可以通过集合的索引获得元组的度量。请帮忙,如果你需要更多信息,请告诉我。谢谢

您应该从集合中提取位于位置
[Measures].[PercentileInt]
的元组,并将度量值添加到其中,以构建包含四个元素的元组。然后,您希望将其值作为度量值
PercentileLo
,即返回。E定义

Member [Measures].[PercentileLo] as
(
[Measures].[Profit],
Order(
NonEmpty(
    [Calendar].[Hierarchy].members * 
    [Region Dim].[Region].members * 
    [Product Dim].[Product].members,
    [Measures].[Profit]),
    [Measures].[Profit], BDESC)).Item([Measures].[PercentileInt])
)
按照您实现它的方式,您尝试从只包含三个元素的元组中提取第四个(当
Item()
从零开始计数时)项。您的有序集只有三个层次结构


另一个无关的评论:我认为您应该避免对
[Calendar].[Hierarchy].members
[Region Dim].[Region].members
[Product Dim].[Product].members
使用完整的层次结构。您的代码看起来在计算中包含了所有级别(包括all成员)。但是我不知道多维数据集的结构和名称,因此我可能会有错误。

另一种方法是查找表中最后20%记录的中位数。我使用了这些函数的组合来找到第75百分位。通过将记录计数除以5,可以使用TopCount函数返回一组元组,这些元组占按目标度量值降序排序的整个表的20%。然后,中位数函数应将您定位到正确的第90百分位值,而无需找到记录的坐标。在我自己的使用中,我对Median和TopCount函数中的最后一个参数使用相同的度量

这是我的密码:

WITH MEMBER Measures.[90th Percentile] AS MEDIAN(
    TOPCOUNT(
        [set definition]
        ,Measures.[Fact Table Record Count] / 5
        ,Measures.[Value by which to sort the set so the first 20% of records are chosen]
    )
    ,Measures.[Value from which the median should be determined]
)
根据您在问题定义中提供的内容,我希望您的代码如下所示:

WITH MEMBER Measures.[90th Percentile] AS MEDIAN(
    TOPCOUNT(
        {
           [Calendar].[Hierarchy].members * 
           [Region Dim].[Region].members * 
           [Product Dim].[Product].members
        }
        ,Measures.[Fact Table Record Count] / 5
        ,[Measures].[Profit]
    )
    ,[Measures].[Profit]
)

这样地?成员[Measures].[PercentileLo]作为顺序(非空([Calendar].[Hierarchy].[Region].[Region].[Region].[Product].[Product].[Product].[profect].[profect].[profect].[PercentileInt].@Prashant你说的“不起作用”是什么意思?只有这句话,我不知道如何改进我的答案。你收到错误信息了吗?上面说什么?它是否运行但给出的值与您期望的值不同?如果是这样的话,您期望得到什么?返回值是多少?对不起,我应该更明确一些。我在PercentileLo列中得到(null)值,这是意外的。我在想,既然我可以用item(index)来获取维度,那么是否可以使用select来获取where条件来获取度量呢?并将其存储为成员。我正试图建立一个计算出的百分位数。