无论选择器如何,MDX都会计算成员

时间:2016-02-26 12:17:40

标签: mdx

我有一个MDX脚本,如;

select NON EMPTY {[Measures].[Miktar Kg]} ON COLUMNS , NON EMPTY [DimSalesRepView].[SalesRepName].[SalesRepName]* [DimDateView].[MonthOfYear].[MonthOfYear] ON ROWS FROM ( SELECT ([DimDateView].[Year].&[2016]}) ON COLUMNS FROM ( SELECT ( [DimCompanyView].[CompanyKey].&[smr]) ON COLUMNS FROM [Model]))

我可以得到理想的结果。我想要实现的是定义另一个计算的度量,它将始终显示[Miktar Kg],无论选择器,过滤器等等。

- - Miktar Kg AllTimesMiktarKg SELIM 1 8089259 27499099 SELIM 2 2591473 27499099 YASAR 1 11384002 27499099 YASAR 2 5434365 27499099

我必须在脚本中执行此操作,而不是在多维数据集中执行此操作。

感谢。

1 个答案:

答案 0 :(得分:1)

您可以为All添加一个元组,这将添加一行:

SELECT 
  NON EMPTY 
    {[Measures].[Miktar Kg]} ON COLUMNS
 ,NON EMPTY 
    {
        [DimSalesRepView].[SalesRepName].[SalesRepName]
      * 
        [DimDateView].[MonthOfYear].[MonthOfYear]
     ,(
        [DimSalesRepView].[SalesRepName].[All]
       ,[DimDateView].[MonthOfYear].[All]
      )
    } ON ROWS
FROM 
(
  SELECT 
    [DimDateView].[Year].&[2016] ON 0
  FROM 
  (
    SELECT 
      [DimCompanyView].[CompanyKey].&[smr] ON 0
    FROM [Model]
  )
);

要添加总计列,您需要使用WITH子句创建计算成员:

WITH MEMBER [Measures].[AllTimesMiktarKg] AS
      (
        [DimSalesRepView].[SalesRepName].[All]
       ,[DimDateView].[MonthOfYear].[All]
       ,[Measures].[Miktar Kg]
      )
SELECT 
  NON EMPTY 
    {
      [Measures].[Miktar Kg]
     ,[Measures].[AllTimesMiktarKg] 
    } ON 0
 ,NON EMPTY 
        [DimSalesRepView].[SalesRepName].[SalesRepName]
      * [DimDateView].[MonthOfYear].[MonthOfYear]
     ON 1
FROM 
(
  SELECT 
    [DimDateView].[Year].&[2016] ON 0
  FROM 
  (
    SELECT 
      [DimCompanyView].[CompanyKey].&[smr] ON 0
    FROM [Model]
  )
);