MDX:如何在另一列中获取列的总和

时间:2017-10-24 07:34:43

标签: ssas mdx

enter image description here

这里我有一个属性TotalPatientCnt值是(30,2013,39),我需要TotalPatientCnt的TotalSum(2082)再增加一个属性。

WITH 
MEMBER [ProgramNames] AS [DimPatientProgram].[Program Key].CURRENTMEMBER.MEMBER_CAPTION 
MEMBER [ProgramKey]   AS [DimPatientProgram].[Program Key].CURRENTMEMBER.MEMBER_Key 
MEMBER TotalPatientCnt AS [Measures].[HealthPlanPatientCnt] 
MEMBER MetricPercent AS [Measures].[ProgramPatientKeyCnt] * 1 / TotalPatientCnt * 100 ,format_string = '#,##.00' 
SELECT {  [ProgramKey] , 
          [ProgramNames] , 
          [Measures].[ProgramPatientKeyCnt] , 
          [TotalPatientCnt] , 
          [MetricPercent] } ON COLUMNS, 
Order (NONEMPTY([DimPatientProgram].[Program Key].[Program Key],
                [Measures].[ProgramPatientKeyCnt]),
      [Measures].[ProgramPatientKeyCnt],BASC) ON ROWS 
FROM [PopulationReportCube] 
WHERE ([DimReport].[Report Key].[Care Management Metric],
       [DimAnchorDate].[Date Key].&[20170930],
       [DimHealthPlan].[Health Plan Key].[Health Plan Key])

1 个答案:

答案 0 :(得分:1)

尝试将您的行设置移动到WITH子句中:

WITH 
MEMBER [ProgramNames] AS 
  [DimPatientProgram].[Program Key].CURRENTMEMBER.MEMBER_CAPTION 
MEMBER [ProgramKey]   AS 
  [DimPatientProgram].[Program Key].CURRENTMEMBER.MEMBER_Key 
MEMBER TotalPatientCnt AS 
  [Measures].[HealthPlanPatientCnt] 
MEMBER MetricPercent AS 
  [Measures].[ProgramPatientKeyCnt] * 1 / TotalPatientCnt * 100 ,format_string = '#,##.00' 
SET [RowsSet] AS
    Order (
      NONEMPTY([DimPatientProgram].[Program Key].[Program Key],
                [Measures].[ProgramPatientKeyCnt]),
      [Measures].[ProgramPatientKeyCnt]
    ,BASC)
SELECT {  [ProgramKey] , 
          [ProgramNames] , 
          [Measures].[ProgramPatientKeyCnt] , 
          [TotalPatientCnt] , 
          [MetricPercent] } ON COLUMNS, 
[RowsSet] ON ROWS 
FROM [PopulationReportCube] 
WHERE ([DimReport].[Report Key].[Care Management Metric],
       [DimAnchorDate].[Date Key].&[20170930],
       [DimHealthPlan].[Health Plan Key].[Health Plan Key]);

然后创建一个跨越所有集合的新度量:

WITH 
MEMBER [ProgramNames] AS 
  [DimPatientProgram].[Program Key].CURRENTMEMBER.MEMBER_CAPTION 
MEMBER [ProgramKey]   AS 
  [DimPatientProgram].[Program Key].CURRENTMEMBER.MEMBER_Key 
MEMBER TotalPatientCnt AS 
  [Measures].[HealthPlanPatientCnt] 
MEMBER [Measures].MetricPercent AS 
  [Measures].[ProgramPatientKeyCnt] * 1 / TotalPatientCnt * 100 ,format_string = '#,##.00' 
SET [RowsSet] AS
    Order (
      NONEMPTY([DimPatientProgram].[Program Key].[Program Key],
                [Measures].[ProgramPatientKeyCnt]),
      [Measures].[ProgramPatientKeyCnt]
    ,BASC)
MEMBER [Measures].[TotalCnt] AS 
  SUM(
    [RowsSet]
    ,[Measures].[HealthPlanPatientCnt] 
  )
SELECT {  [ProgramKey] , 
          [ProgramNames] , 
          [Measures].[ProgramPatientKeyCnt] , 
          [TotalPatientCnt] ,
          [Measures].[TotalCnt], 
          [MetricPercent] } ON COLUMNS, 
[RowsSet] ON ROWS 
FROM [PopulationReportCube] 
WHERE ([DimReport].[Report Key].[Care Management Metric],
       [DimAnchorDate].[Date Key].&[20170930],
       [DimHealthPlan].[Health Plan Key].[Health Plan Key]);