【问题标题】:Calculating percentile values in SSAS在 SSAS 中计算百分位值
【发布时间】:2014-03-05 16:45:47
【问题描述】:

我正在尝试计算立方体中的百分位数(例如我测量的第 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]

我认为必须有一种方法来衡量通过集合索引找到的元组。请帮助,如果您需要更多信息,请告诉我。谢谢!

【问题讨论】:

    标签: ssas mdx business-intelligence olap-cube percentile


    【解决方案1】:

    您应该从集合中提取位于位置[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 使用完整的层次结构。您的代码看起来像是在计算中包括所有级别(包括所有成员)。但我不知道你的立方体的结构和名称,因此我可能错了。

    【讨论】:

    • 这样吗?成员 [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])
    • @Prashant “不起作用”是什么意思?仅凭这句话,我不知道如何改进我的答案。您收到错误消息吗?它说什么?它是否运行但给出的值与您预期的不同?如果是这样,您期望什么,返回值是什么?
    • 对不起,我应该更明确一点。我在 PercentileLo 列中得到(空)值,这是出乎意料的。我在想,既然我可以使用 item(index) 获取维度,是否可以使用 select 来获取 where 条件来获取度量?并将其存储为成员。我正在尝试建立一个计算过的百分位数。
    【解决方案2】:

    另一种方法是查找表中最后 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]
    )
    

    【讨论】:

      猜你喜欢
      • 2019-03-27
      • 1970-01-01
      • 2017-12-03
      • 2011-10-10
      • 2011-12-29
      • 2013-06-20
      • 2017-10-12
      • 2017-10-19
      • 1970-01-01
      相关资源
      最近更新 更多