简体   繁体   English

如何重组MDX以将计算的度量分组到新的行标签下

[英]How to restructure MDX to group calculated measures under new row label

I the following MDX that queries a set of calculated measures for two metrics over a date range (months): 我使用以下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])

The result set looks like this: 结果集如下所示:

+-----------------------------+-----------------------------+---------------------------+--------------------------+------------------------------------+-------------------------------------+-----------------------------------+---------------------------------+--------------------------------------------+
|                             |  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%                   |
+-----------------------------+-----------------------------+---------------------------+--------------------------+------------------------------------+-------------------------------------+-----------------------------------+---------------------------------+--------------------------------------------+

I just have the [Date Post Transaction].[Calendar Month Period].&[201301] in there, which displays the row 201301 , as a filler. 我只有[Date Post Transaction].[Calendar Month Period].&[201301] ,其中显示行201301作为填充。 It doesn't seem to return a result set without a row axis label there. 它似乎没有返回没有行轴标签的结果集。

The format that I need to get the result set into looks like this: 我需要将结果集放入的格式如下所示:

+---------------------------------+----------------------+---------------------+-----------------------+----------------------+
|                                 |        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%         |
+---------------------------------+----------------------+---------------------+-----------------------+----------------------+

or even better: 甚至更好:

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

So, I was thinking about some logic that works to group the calculated measures like this: 因此,我在考虑一些逻辑来将计算出的度量进行分组,如下所示:

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])

But this doesn't work. 但这是行不通的。 Thoughts? 有什么想法吗?

Using any hierarchy not used so far in your query (i will use [Dim1].[Util] in my example, as I do not know your cube), you would create members on this - as you can create calculated members on any hierarchy, not just on the Measures hierarchy: 使用到目前为止查询中未使用的任何层次结构(在我的示例中,我将使用[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])

There is no specific requirement on the hierarchy to use in the columns, except that it should not otherwise be used in your query. 对列中使用的层次结构没有特殊要求,除非在查询中不应使用它。 Some cube designers explicitly create one or even two utility dimensions in each cube, which contain just one dummy member in order to be able to easily write queries like this. 一些多维数据集设计器在每个多维数据集中显式创建一个或什至两个实用程序维度,这些维度仅包含一个虚拟成员,以便能够像这样轻松地编写查询。 These dimensions are then just used to create calculated members on them. 这些尺寸仅用于在其上创建计算的成员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM