0

下面的 MDX 查询一个日期范围(月)内两个指标的一组计算度量:

WITH
MEMBER [Measures].[Prior Visits Office New] as SUM({[Date Post Transaction].[Calendar Month Period].&[201211].Lag(12) : [Date Post Transaction].[Calendar Month Period].&[201306].Lag(12)},[Measures].[Visits Office New]),format_string = '#,##0' 
MEMBER [Measures].[Current Visits Office New] as SUM({[Date Post Transaction].[Calendar Month Period].&[201211] : [Date Post Transaction].[Calendar Month Period].&[201306]},[Measures].[Visits Office New]),format_string = '#,##0' 
MEMBER [Measures].[Diff Visits Office New] as ([Measures].[Current Visits Office New] - [Measures].[Prior Visits Office New]),format_string = '#,##0' 
MEMBER [Measures].[Percent Change Visits Office New] as ([Measures].[Diff Visits Office New] / [Measures].[Prior Visits Office New]),format_string = 'Percent'
MEMBER [Measures].[Prior Visits Office Established] as SUM({[Date Post Transaction].[Calendar Month Period].&[201211].Lag(12) : [Date Post Transaction].[Calendar Month Period].&[201306].Lag(12)},[Measures].[Visits Office Established]),format_string = '#,##0' 
MEMBER [Measures].[Current Visits Office Established] as SUM({[Date Post Transaction].[Calendar Month Period].&[201211] : [Date Post Transaction].[Calendar Month Period].&[201306]},[Measures].[Visits Office Established]),format_string = '#,##0' 
MEMBER [Measures].[Diff Visits Office Established] as ([Measures].[Current Visits Office Established] - [Measures].[Prior Visits Office Established]),format_string = '#,##0' 
MEMBER [Measures].[Percent Change Visits Office Established] as ([Measures].[Diff Visits Office Established] / [Measures].[Prior Visits Office Established]),format_string = 'Percent'
SELECT {[Measures].[Current Visits Office New],[Measures].[Prior Visits Office New],[Measures].[Diff Visits Office New],[Measures].[Percent Change Visits Office New],[Measures].[Current Visits Office Established],[Measures].[Prior Visits Office Established],[Measures].[Diff Visits Office Established],[Measures].[Percent Change Visits Office Established]}
ON COLUMNS , NON EMPTY Hierarchize(AddCalculatedMembers({DrilldownLevel({[Date Post Transaction].[Calendar Month Period].Children})}))  
ON ROWS FROM (SELECT ({[Date Post Transaction].[Calendar Month Period].&[201301]}) 
ON COLUMNS FROM [cube])
WHERE ([Report Group].[Report Group1].&[Group])

结果集如下所示:

+-----------------------------+-----------------------------+---------------------------+--------------------------+------------------------------------+-------------------------------------+-----------------------------------+---------------------------------+--------------------------------------------+
|                             |  Current Visits Office New  |  Prior Visits Office New  |  Diff Visits Office New  |  Percent Change Visits Office New  |  Current Visits Office Established  |  Prior Visits Office Established  |  Diff Visits Office Established |  Percent Change Visits Office Established  |
+-----------------------------+-----------------------------+---------------------------+--------------------------+------------------------------------+-------------------------------------+-----------------------------------+---------------------------------+--------------------------------------------+
|            201301           |            4,793            |           4,307           |             486          |               11.28%               |                 58,979              |                57,228             |               1,751             |                    3.06%                   |
+-----------------------------+-----------------------------+---------------------------+--------------------------+------------------------------------+-------------------------------------+-----------------------------------+---------------------------------+--------------------------------------------+

我只是[Date Post Transaction].[Calendar Month Period].&[201301]在那里,它显示 row 201301,作为填充物。它似乎没有返回没有行轴标签的结果集。

我需要将结果集转换为如下格式:

+---------------------------------+----------------------+---------------------+-----------------------+----------------------+
|                                 |        Current       |        Prior        |          Diff         |    Percent Change    |  
+---------------------------------+----------------------+---------------------+-----------------------+----------------------+
|    Visits Office New            |         4,793        |        4,307        |           486         |        11.28%        |
+---------------------------------+----------------------+---------------------+-----------------------+----------------------+
|    Visits Office Established    |        58,979        |        57,228       |          1,751        |        3.06%         |
+---------------------------------+----------------------+---------------------+-----------------------+----------------------+

甚至更好:

+---------------------------------+----------------------+---------------------+-----------------------+----------------------+
|    Visits Office New            |         4,793        |        4,307        |           486         |        11.28%        |
+---------------------------------+----------------------+---------------------+-----------------------+----------------------+
|    Visits Office Established    |        58,979        |        57,228       |          1,751        |        3.06%         |
+---------------------------------+----------------------+---------------------+-----------------------+----------------------+

所以,我在考虑一些逻辑,可以像这样对计算的度量进行分组:

WITH
MEMBER [Measures].[Visits Office New] as (
    MEMBER [Measures].[Prior Visits Office New] as SUM({[Date Post Transaction].[Calendar Month Period].&[201211].Lag(12) : [Date Post Transaction].[Calendar Month Period].&[201306].Lag(12)},[Measures].[Visits Office New]),format_string = '#,##0' 
    MEMBER [Measures].[Current Visits Office New] as SUM({[Date Post Transaction].[Calendar Month Period].&[201211] : [Date Post Transaction].[Calendar Month Period].&[201306]},[Measures].[Visits Office New]),format_string = '#,##0' 
    MEMBER [Measures].[Diff Visits Office New] as ([Measures].[Current Visits Office New] - [Measures].[Prior Visits Office New]),format_string = '#,##0' 
    MEMBER [Measures].[Percent Change Visits Office New] as ([Measures].[Diff Visits Office New] / [Measures].[Prior Visits Office New]),format_string = 'Percent' 
)
MEMBER [Measures].[Visits Office Established] as (
    MEMBER [Measures].[Prior Visits Office Established] as SUM({[Date Post Transaction].[Calendar Month Period].&[201211].Lag(12) : [Date Post Transaction].[Calendar Month Period].&[201306].Lag(12)},[Measures].[Visits Office Established]),format_string = '#,##0'
    MEMBER [Measures].[Current Visits Office Established] as SUM({[Date Post Transaction].[Calendar Month Period].&[201211] : [Date Post Transaction].[Calendar Month Period].&[201306]},[Measures].[Visits Office Established]),format_string = '#,##0' 
    MEMBER [Measures].[Diff Visits Office Established] as ([Measures].[Current Visits Office Established] - [Measures].[Prior Visits Office Established]),format_string = '#,##0' 
    MEMBER [Measures].[Percent Change Visits Office Established] as ([Measures].[Diff Visits Office Established] / [Measures].[Prior Visits Office Established]),format_string = 'Percent'
)
SELECT {[Measures].[Current Visits Office New],[Measures].[Prior Visits Office New],[Measures].[Diff Visits Office New],[Measures].[Percent Change Visits Office New],[Measures].[Current Visits Office Established],[Measures].[Prior Visits Office Established],[Measures].[Diff Visits Office Established],[Measures].[Percent Change Visits Office Established]}
ON COLUMNS , NON EMPTY Hierarchize(AddCalculatedMembers({DrilldownLevel({[Date Post Transaction].[Calendar Month Period].Children})}))  
ON ROWS FROM (SELECT ({[Date Post Transaction].[Calendar Month Period].&[201301]}) 
ON COLUMNS FROM [cube])
WHERE ([Report Group].[Report Group1].&[Group])

但这不起作用。想法?

4

1 回答 1

0

使用到目前为止在您的查询中未使用的任何层次结构(我将[Dim1].[Util]在我的示例中使用,因为我不知道您的多维数据集),您将在此创建成员 - 因为您可以在任何层次结构上创建计算成员,而不仅仅是在Measures层次结构上:

WITH member [Dim1].[Util].[Prior] as
     SUM({[Date Post Transaction].[Calendar Month Period].&[201211].Lag(12) : [Date Post Transaction].[Calendar Month Period].&[201306].Lag(12)},
         [Measures].CurrentMember
        ),format_string = '#,##0'
     member [Dim1].[Util].[Current] as
     SUM({[Date Post Transaction].[Calendar Month Period].&[201211] : [Date Post Transaction].[Calendar Month Period].&[201306]},
         [Measures].CurrentMember
        ),format_string = '#,##0'
     member [Dim1].[Util].[Diff] as
     [Dim1].[Util].[Current] - member [Dim1].[Util].[Prior],format_string = '#,##0'
     member [Dim1].[Util].[Percent Change] as
     [Dim1].[Util].[Diff] / [Dim1].[Util].[Current],format_string = 'Percent'
SELECT {
       [Dim1].[Util].[Prior],
       [Dim1].[Util].[Current],
       [Dim1].[Util].[Diff],
       [Dim1].[Util].[Percent Change]
       }
ON COLUMNS ,
       {
       [Measures].[Visits Office New],
       [Measures].[Visits Office Established]
       }
ON ROWS
  FROM (SELECT ({[Date Post Transaction].[Calendar Month Period].&[201301]}) 
               ON COLUMNS
          FROM [cube])
WHERE ([Report Group].[Report Group1].&[Group])

对于在列中使用的层次结构没有特定要求,除非它不应该在查询中使用。一些多维数据集设计者明确地在每个多维数据集中创建一个甚至两个实用维度,其中仅包含一个虚拟成员,以便能够轻松编写这样的查询。然后,这些维度仅用于在其上创建计算成员。

于 2013-10-10T07:24:21.557 回答