下面的 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])
但这不起作用。想法?