SSRS mdx 报告:在列上使用维度

SSRS mdx report: use dimension on columns

这个简单的 mdx 查询在 SSMS 中有效:

SELECT  
CrossJoin({[Measures].[Qnt]},
          {[Sales_step].CHILDREN}) ON COLUMNS,
[City] ON ROWS  
FROM [SALES_PIPE]

但它未能在 Visual Studio 内 运行 获得 rdl 报告。出现错误:

The query cannot be prepared: The query must have at least one axis. 
The first axis of the query should not have multiple hierarchies, 
nor should it reference any dimension other than the Measures dimension..
Parameter name: mdx (MDXQueryGenerator)

我找到了另一种检索结果的语法,但它的列是硬编码的,而且脚本很慢:

WITH 
MEMBER [Measures].[Contacts] AS 
       CASE WHEN [Sales_step].CURRENTMEMBER IS [Sales_step].&[contact]               
       THEN [Measures].[Qnt] ELSE null END
MEMBER [Measures].[Clients] AS 
       CASE WHEN [Sales_step].CURRENTMEMBER IS [Sales_step].&[client]               
       THEN [Measures].[Qnt] ELSE null END
MEMBER [Measures].[Funded] AS 
       CASE WHEN [Sales_step].CURRENTMEMBER IS [Sales_step].&[funded]               
       THEN [Measures].[Qnt] ELSE null END

SELECT {[Measures].[Contacts],
        [Measures].[Clients],
        [Measures].[Funded]} ON COLUMNS,

NON EMPTY     
FILTER(crossjoin({[City].CHILDREN},                            
                 {[Sales_step].CHILDREN}),
       [Measures].[Contacts] > 0 OR
       [Measures].[Clients] > 0 OR      
       [Measures].[Funded] > 0) ON ROWS 

FROM [SALES_PIPE]

使它变得非常慢的部分 - 不是计算成员,它是城市和行上 Sales_step 维度的交叉连接,我必须制作(否则,城市仅在行上变暗, -我在列上得到空结果)。有什么建议可以让我的 mdx 更快吗?

尝试在 SSRS 中使用以下查询。

SELECT  [Measures].[Qnt] ON COLUMNS,
NonEmpty
        (
         [Sales_step].CHILDREN 
         * 
         [City], [Measures].[Qnt]
        ) ON ROWS       
FROM [SALES_PIPE]

话虽如此,我假设您是在这段代码上方声明命名集 [City]

这是否给出相同的结果?有没有快点?

WITH 
  MEMBER [Measures].[Contacts] AS 
    Sum
    (
      IIF
      (
        [Sales_step].CurrentMember IS [Sales_step].&[contact],
       ,[Measures].[Qnt]
       ,null
      )
    ) 
  MEMBER [Measures].[Clients] AS 
    Sum
    (
      IIF
      (
        [Sales_step].CurrentMember IS [Sales_step].&[client]
       ,[Measures].[Qnt]
       ,null
      )
    ) 
  MEMBER [Measures].[Funded] AS 
    Sum
    (
      IIF
      (
        [Sales_step].CurrentMember IS [Sales_step].&[funded]
       ,[Measures].[Qnt]
       ,null
      )
    ) 
  SET [yourMeasures] AS 
    {
      [Measures].[Contacts]
     ,[Measures].[Clients]
     ,[Measures].[Funded]
    } 
  SET [CitySales] AS 
    [City].Children * [Sales_step].Children 
  SET [CitySalesNonEmpty] AS 
    Union
    (
      NonEmpty([CitySales],[Measures].[Contacts])
     ,NonEmpty([CitySales],[Measures].[Clients])
     ,NonEmpty([CitySales],[Measures].[Funded])
    ) 
/*
//>>>>Alternative syntax for above union>>
  SET [CitySalesNonEmpty] AS 
      NonEmpty([CitySales],[Measures].[Contacts])
     +NonEmpty([CitySales],[Measures].[Clients])
     +NonEmpty([CitySales],[Measures].[Funded])
//>>>>
*/
SELECT 
  [yourMeasures] ON COLUMNS
 ,NON EMPTY 
    [CitySalesNonEmpty] ON ROWS
FROM [SALES_PIPE];

感谢@whytheq 提出的避免使用慢速 Filter() 函数和 CASE 条件的建议 - 我 post 此处使用新的优化代码,其中包含子多维数据集请求和 IIF 条件。它运行得更快:

WITH 
MEMBER [Measures].[Contacts] AS 
       IIF([Sales_step].CURRENTMEMBER IS [Sales_step].&[contact], [Measures].[Qnt], null)
MEMBER [Measures].[Clients] AS 
       IIF([Sales_step].CURRENTMEMBER IS [Sales_step].&[client], [Measures].[Qnt], null)
MEMBER [Measures].[Funded] AS 
       IIF([Sales_step].CURRENTMEMBER IS [Sales_step].&[funded], [Measures].[Qnt], null)

SELECT {[Measures].[Contacts],
        [Measures].[Clients],
        [Measures].[Funded]} ON COLUMNS,

NON EMPTY     
       crossjoin({[City].CHILDREN},                            
                 {[Sales_step].CHILDREN}) ON ROWS 

FROM ( SELECT ( [Sales_step].MEMBERS ) ON COLUMNS
FROM [SALES_PIPE])