展平MDX查询以在Query-designer中接受

时间:2014-02-05 11:03:09

标签: ssas ssms mdx

以下查询在SSMS中完美运行,但由于我在COLUMNS轴上定义了维度,因此在查询设计器中不起作用:

SELECT 
    NON EMPTY { 
        [Measures].[Amount]
        * [Cost Type].[Cost Type].[Cost Type]
    } ON COLUMNS
    , NON EMPTY { 
        [Empl].[Name].[Name]
        * [Date].[Calendar].[Month]
    } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM 
    Cube

要解决此问题,我已按以下方式弄平了查询:

SELECT t.* 
FROM (

    SELECT 
        NON EMPTY { 
            [Measures].[Amount]
            * [Cost Type].[Cost Type].[Cost Type]
        } ON COLUMNS
        , NON EMPTY { 
            [Empl].[Name].[Name]
            * [Date].[Calendar].[Month]
        } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
    FROM 
        Cube

) AS t

这在SSMS中非常有用,就像第一个查询一样。但是,这会导致Query-designer中出现以下错误:

TITLE: Microsoft Visual Studio
------------------------------

Query preparation failed.

------------------------------
ADDITIONAL INFORMATION:

Please verify that the query is an MDX one and not DMX. (Microsoft.AnalysisServices.Controls)

------------------------------
BUTTONS:

OK
------------------------------

这是我正在寻找的结果:

Name     Month     Cost_Type1     Cost_Type2     Cost_Type3
a        january   1.54           1.56           2.43
a        january   3.53           2.34           1.23
b        january   3.53           2.13           4.53

如何在Query-designer(来自BIDS,Visual Studio)中使用此查询?

1 个答案:

答案 0 :(得分:1)

由于您希望在每个[成本类型]的列上重复[度量]。[金额]度量,因此除了为每种成本类型创建计算成员之外别无选择:

WITH 
MEMBER [Cost_Type1] AS ([Cost Type].[Cost Type].[Cost_Type1], [Measures].[Amount])
MEMBER [Cost_Type2] AS ([Cost Type].[Cost Type].[Cost_Type2], [Measures].[Amount])
MEMBER [Cost_Type3] AS ([Cost Type].[Cost Type].[Cost_Type3], [Measures].[Amount])

SELECT { [Cost_Type1], [Cost_Type2], [Cost_Type3] } ON COLUMNS,
    NON EMPTY { 
        [Empl].[Name].[Name]
        * [Date].[Calendar].[Month]
    } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM 
    Cube

这是由于BIDS查询设计器的限制 - 它不允许在“设计时”使用未知数量的列,因此无法在COLUMNS轴上指定一组 - 仅限单个成员(即使它在SSMS中运行良好。)