调整TOPCOUNT以节省时间

时间:2013-11-18 12:59:04

标签: mdx

获得了以下脚本,但它似乎将NumDeals的前15名客户拉回了他们所有时间 - 而不是过去7天。

如何调整设置以反映此要求?

WITH 
    SET [Set_7Days] as
        TAIL ([Date].[Date - Calendar Month].[Calendar Day], 7)
    SET [Set_Top15Customers] as
         {
          TOPCOUNT (
           [CustomerDim].[CustomerDim].[CustomerLevel].members,
           15,
            ( 
            [Date].[Date - Calendar Month].currentmember, 
            [Measures].[NumDeals] 
            )
          )
         }
SELECT 
    NON EMPTY
        [Set_7Days]
    ON COLUMNS,
    NON EMPTY
        [Set_Top15Customers]
    ON ROWS
FROM [ourCube]
WHERE ( 
    [Measures].[NumDeals] 
    ) 

修改

使用mmarie帮助我有以下内容:想要将内容保存在自定义集中,以便我可以将其添加到与PIVOT中的CUBE相关联的EXCEL:< / p>

WITH 
    SET  as
        TAIL ([Date].[Date - Calendar Month].[Calendar Day], 7)
    SET [Set_Top15Customers] as
         {
          TOPCOUNT (
           [CustomerDim].[CustomerDim].[CustomerLevel].members,
           15,
           Sum(
                   [Set_7Days], //TAIL([Date].[Date - Calendar Month].[Calendar Day], 7), 
                   [Measures].[NumDeals]
                   )
          )
         }
SELECT 
    NON EMPTY
        [Set_7Days]
    ON COLUMNS,
    NON EMPTY
        [Set_Top15Customers]
    ON ROWS
FROM [ourCube]
WHERE ( 
    [Measures].[NumDeals] 
    ) 

1 个答案:

答案 0 :(得分:2)

您需要将日期过滤器添加到最高计数中。可能有几种方法可以做到这一点。这个可行,但你可能需要检查性能是否可以接受。

试试这个:

with
member [measures].[Num Deals last 7 days] as  
Sum(Head([Date].[Date - Calendar Month].[Calendar Day], 7), [Measures].[NumDeals])

select 
NON Empty {TAIL ([Date].[Date - Calendar Month].[Calendar Day], 7)[measures].[Num Deals Last 7 days]} on 0,
NON Empty {topcount( {[CustomerDim].[CustomerDim].[CustomerLevel].members}, 5, measures.[Num Deals last 7 days])} on 1
FROM [ourCube]
WHERE ( [Measures].[NumDeals] )