MDX在MDX studio中工作正常。在SSRS中使用它后,出现以下错误:“查询必须至少具有一个轴。第一个轴..”

时间:2019-03-26 09:42:42

标签: reporting-services mdx

使用 MDX studio 时,我的代码运行良好,一旦在SSRS中使用相同的代码,就会收到错误消息:“无法准备查询:查询必须至少具有一个轴

我尝试切换行和列,并且遇到了类似的问题,但是无法使用这些解决方案复制所需的输出

WITH 
    MEMBER [Version].[Version].[Product Long Desc] AS 
         iif([Product].[Product].CurrentMember.Level.Ordinal=1, "TOTAL",[Product].[Product].CurrentMember.Member_Caption) 
    MEMBER [Measures].[Trans] AS iif([Product].[Product].CurrentMember.Level.Ordinal=1,
         [Measures].[Customers],[Measures].[Transactions]) 
    MEMBER [Measures].[ACP] AS iif([Product].[Product].CurrentMember.Level.Ordinal=1,
         [Measures].[ACP Customers],[Measures].[ACP Transactions]) 
    MEMBER [Measures].[AIC] AS iif([Product].[Product].CurrentMember.Level.Ordinal=1,
         [Measures].[AIC Customers],[Measures].[AIC Transactions]) MEMBER [Version].[Version].[Measure Name] 
            AS CASE [Measures].CurrentMember.Member_Caption WHEN "Sales Units" 
            THEN "UNITS" WHEN "Customers" THEN "TRANS." WHEN "Transactions" THEN "TRANS." 
            WHEN "ACP Customers" THEN "ACP" WHEN "AIC Customers" THEN "AIC" WHEN "Reg Sales Avg Retail Selling Price" 
            THEN "AIP" ELSE [Measures].CurrentMember.Member_Caption END 
    MEMBER [Version].[Version].[Comparable LY Perc] AS 
        ([Version].[Version].[Version No].[ACT % ON LY],[Like for Like].[Like for Like].[Like for Like Adj Ind].&[1]) 
    MEMBER [Version].[Version].[Actual YTD] AS 
        ([Version].[Version].[Version No].&[1],[Accumulation].[Accumulation].[YTD]) 
    MEMBER [Version].[Version].[LY YTD] AS 
        ([Version].[Version].[Version No].&[5],[Accumulation].[Accumulation].[YTD]) 
    MEMBER [Version].[Version].[Comparable LY Perc YTD] AS 
        ([Version].[Version].[Version No].[ACT % ON LY],[Like for Like].[Like for Like].[Like for Like Adj Ind].&[1],[Accumulation].[Accumulation].[YTD]) 
      MEMBER [Version].[Version].[LY Perc YTD] AS 
        ([Version].[Version].[Version No].[ACT % ON LY],[Accumulation].[Accumulation].[YTD]) 
    MEMBER [Product].[Product].[TOTAL C&GM] AS 
        Aggregate({[Product].[Product].[Business Unit No].&[4],[Product].[Product].[Business Unit No].&[5],[Product].[Product].[Business Unit No].&[6],[Product].[Product].[Business Unit No].&[7]}) 
    MEMBER [Product].[Product].[TOTAL C&GM (Incl CRG)] AS 
        Aggregate({[Product].[Product].[Business Unit No].&[4],[Product].[Product].[Business Unit No].&[5],[Product].[Product].[Business Unit No].&[6],[Product].[Product].[Business Unit No].&[7],[Product].[Product].[Business Unit No].&[8]}) 
    SELECT {[Version].[Version].[Product Long Desc],[Version].[Version].[Measure Name],[Version].[Version].[Version No].&[1],[Version].[Version].[Version No].&[5],[Version].[Version].[Comparable LY Perc],[Version].[Version].[Version No].[ACT % ON LY],[Version].[Version].[Actual YTD],[Version].[Version].[LY YTD], 
 [Version].[Version].[Comparable LY Perc YTD],[Version].[Version].[LY Perc YTD]} ON COLUMNS,({[Product].[Product].[Company No].&[2],[Product].[Product].[Business Unit No].&[4],[Product].[Product].[Business Unit No].&[5],[Product].[Product].[Business Unit No].&[6],[Product].[Product].[Business Unit No].&[7],[Product].[Product].[TOTAL C&GM], 
 [Product].[Product].[Business Unit No].&[8],[Product].[Product].[TOTAL C&GM (Incl CRG)],[Product].[Product].[Business Unit No].&[3]},{[Measures].[Sales],[Measures].[Sales Units],[Measures].[Trans],[Measures].[ACP],[Measures].[AIC],[Measures].[Reg Sales Avg Retail Selling Price]}) 
ON ROWS FROM [WW Performance Business View]WHERE ([Location].[Location].[Chain No].&[243],tail(Filter([Time].[Time].[Fin Week],[Time].[Time].Properties( "Compl Wk Ind" )="1"),1).item(0))

尽可能使代码在Visual Studio中像在MDX Studio中一样运行

2 个答案:

答案 0 :(得分:0)

MDX!很大的脚本。 我开始稍微更改格式以查看发生了什么:

WITH 
    MEMBER [Version].[Version].[Product Long Desc] AS 
         iif(
              [Product].[Product].CurrentMember.Level.Ordinal=1, "TOTAL",[Product]. 
              [Product].CurrentMember.Member_Caption) 
    MEMBER [Measures].[Trans] AS iif([Product].[Product].CurrentMember.Level.Ordinal=1,
         [Measures].[Customers],[Measures].[Transactions]) 
    MEMBER [Measures].[ACP] AS iif([Product].[Product].CurrentMember.Level.Ordinal=1,
         [Measures].[ACP Customers],[Measures].[ACP Transactions]) 
    MEMBER [Measures].[AIC] AS iif([Product].[Product].CurrentMember.Level.Ordinal=1,
         [Measures].[AIC Customers],[Measures].[AIC Transactions]) MEMBER [Version].[Version].[Measure Name] 
            AS CASE [Measures].CurrentMember.Member_Caption WHEN "Sales Units" 
            THEN "UNITS" WHEN "Customers" THEN "TRANS." WHEN "Transactions" THEN "TRANS." 
            WHEN "ACP Customers" THEN "ACP" WHEN "AIC Customers" THEN "AIC" WHEN "Reg Sales Avg Retail Selling Price" 
            THEN "AIP" ELSE [Measures].CurrentMember.Member_Caption END 
    MEMBER [Version].[Version].[Comparable LY Perc] AS 
        ([Version].[Version].[Version No].[ACT % ON LY],[Like for Like].[Like for Like].[Like for Like Adj Ind].&[1]) 
    MEMBER [Version].[Version].[Actual YTD] AS 
        ([Version].[Version].[Version No].&[1],[Accumulation].[Accumulation].[YTD]) 
    MEMBER [Version].[Version].[LY YTD] AS 
        ([Version].[Version].[Version No].&[5],[Accumulation].[Accumulation].[YTD]) 
    MEMBER [Version].[Version].[Comparable LY Perc YTD] AS 
        ([Version].[Version].[Version No].[ACT % ON LY],[Like for Like].[Like for Like].[Like for Like Adj Ind].&[1],[Accumulation].[Accumulation].[YTD]) 
      MEMBER [Version].[Version].[LY Perc YTD] AS 
        ([Version].[Version].[Version No].[ACT % ON LY],[Accumulation].[Accumulation].[YTD]) 
    MEMBER [Product].[Product].[TOTAL C&GM] AS 
        Aggregate({[Product].[Product].[Business Unit No].&[4],[Product].[Product].[Business Unit No].&[5],[Product].[Product].[Business Unit No].&[6],[Product].[Product].[Business Unit No].&[7]}) 
    MEMBER [Product].[Product].[TOTAL C&GM (Incl CRG)] AS 
        Aggregate({[Product].[Product].[Business Unit No].&[4],[Product].[Product].[Business Unit No].&[5],[Product].[Product].[Business Unit No].&[6],[Product].[Product].[Business Unit No].&[7],[Product].[Product].[Business Unit No].&[8]}) 

SELECT 
{
[Version].[Version].[Product Long Desc]
,[Version].[Version].[Measure Name]
,[Version].[Version].[Version No].&[1]
,[Version].[Version].[Version No].&[5]
,[Version].[Version].[Comparable LY Perc]
,[Version].[Version].[Version No].[ACT % ON LY]
,[Version].[Version].[Actual YTD]
,[Version].[Version].[LY YTD]
,[Version].[Version].[Comparable LY Perc YTD],[Version].[Version].[LY Perc YTD]} 
ON COLUMNS

,({[Product].[Product].[Company No].&[2],[Product].[Product].[Business Unit No].&[4],[Product].[Product].[Business Unit No].&[5],[Product].[Product].[Business Unit No].&[6],[Product].[Product].[Business Unit No].&[7],[Product].[Product].[TOTAL C&GM], 
 [Product].[Product].[Business Unit No].&[8],[Product].[Product].[TOTAL C&GM (Incl CRG)],[Product].[Product].[Business Unit No].&[3]},{[Measures].[Sales],[Measures].[Sales Units],[Measures].[Trans],[Measures].[ACP],[Measures].[AIC],[Measures].[Reg Sales Avg Retail Selling Price]}) 
ON ROWS 
FROM [WW Performance Business View]
WHERE ([Location].[Location].[Chain No].&[243],tail(Filter([Time].[Time].[Fin Week],[Time].[Time].Properties( "Compl Wk Ind" )="1"),1).item(0));

....然后我意识到了问题:在SSRS中,您只能将[measures]放在列中。使用SSRS时受到MDX的限制,因此您将需要重新编写脚本...对不起,这不是一个好的答案,而仅仅是该工具的限制。

以下是确认某些限制的参考:https://social.msdn.microsoft.com/Forums/sqlserver/en-US/0d2b3e04-0fae-418b-a7ed-01c26147b839/mdx-works-fine-in-ssms-but-not-in-query-designer?forum=sqlreportingservices

p.s。 MDX Studio石头!我希望MS已采纳并进一步发展它。

答案 1 :(得分:0)

我为此问题苦苦挣扎的原因是因为MDX Studio不允许一个创建两个以上的轴并产生错误,而当我有两个轴并且可以在MDX Studio中工作时,SSRS抱怨列上的度量,因此我没有重写我的MDX,而是在SSRS中开发了第3轴,使用矩阵来使我的列不旋转,该列将放置在行上。这是快速可靠的解决方案。但是请注意,如果采用这种方法,则必须在SSRS中而不是在MDX studio中进行开发。感谢您的帮助