0

I have a scenario where a result set has to be bucketed and assign a frequency.

For example, the following MDX query:

WITH MEMBER [MEASURES].[PERC_1] AS
    AGGREGATE ( EXISTING  [DIM CUSTOMER].[CUSTOMER ID].[ALL].CHILDREN,[MEASURES].[AMOUNT])

SELECT
[MEASURES].[PERC_1] ON 0,
[DIM CUSTOMER].[CUSTOMER ID].CHILDREN,[DIM CUSTOMER].[NAME].CHILDREN        
FROM [ANALYSIS DW]
WHERE ([DIM CUSTOMER].[ADDRESS].[ALL])

should return this result:

     Perc1
 C1   10
 C2   0
 C3   20
 C4   30
 C5   40
 C6   50
 C7   50 
 C8   50 
 C9   90
 C10  100

Now, I want this result set to be divided into buckets. If my bucket size is 3, the buckets should be

  • 0-30
  • 31-60
  • 61-100

These buckets are calculated based on the maximum and minimum values of the perc_1 measure above; i.e., 0 is minimum and 100 is maximum. Buckets are calculated as (0+100)/3 -- (0-30, 31-60, 61-100).

Now the results after the frequency distribution on the above result set should look as below -

         frequency
 0-30      4
 31-60     4 
 61-100    2

I will not get the access to the OLTP design/SSAS Cube solution.

4

1 回答 1

2
WITH SET [0-30 set] AS
         Filter([DIM CUSTOMER].[CUSTOMER ID].CHILDREN,
                [MEASURES].[PERC_1] >= 0 AND [MEASURES].[PERC_1] <= 30
               )
     SET [31-60 set] AS
         Filter([DIM CUSTOMER].[CUSTOMER ID].CHILDREN,
                [MEASURES].[PERC_1] >= 31 AND [MEASURES].[PERC_1] <= 60
               )
     SET [61-100 set] AS
         Filter([DIM CUSTOMER].[CUSTOMER ID].CHILDREN,
                [MEASURES].[PERC_1] >= 61 AND [MEASURES].[PERC_1] <= 100
               )
     MEMBER [DIM CUSTOMER].[CUSTOMER ID].[0-30] AS
            NULL
     MEMBER [DIM CUSTOMER].[CUSTOMER ID].[31-60] AS
            NULL
     MEMBER [DIM CUSTOMER].[CUSTOMER ID].[61-100] AS
            NULL
     MEMBER [Measures].[frequency] AS
            CASE [DIM CUSTOMER].[CUSTOMER ID].CurrentMember
                 WHEN [DIM CUSTOMER].[CUSTOMER ID].[0-30] THEN
                      [0-30 set].Count
                 WHEN [DIM CUSTOMER].[CUSTOMER ID].[31-60] THEN
                      [31-60 set].Count
                 WHEN [DIM CUSTOMER].[CUSTOMER ID].[61-100] THEN
                      [61-100 set].Count
            END
SELECT { [Measures].[frequency] } ON 0,
       { 
         [DIM CUSTOMER].[CUSTOMER ID].[0-30],
         [DIM CUSTOMER].[CUSTOMER ID].[31-60],
         [DIM CUSTOMER].[CUSTOMER ID].[61-100]
       } ON 1
  FROM [ANALYSIS DW]
WHERE ([DIM CUSTOMER].[ADDRESS].[ALL])

我认为您不能完全在 MDX 中以“3”作为 MDX 查询的参数的方式执行此操作,因为您至少需要在 MDX 语句中明确地拥有类似于存储桶的成员定义的内容。WITH 子句(或会话级 CREATE 语句)是唯一可以创建行轴上显示的成员的地方,即使它们仅用作占位符并且不包含任何逻辑。

您将需要一个外部工具来生成上述参数特定的 MDX 语句。

于 2014-01-08T17:45:44.343 回答