使用mdx并排组合两个结果集

时间:2015-02-20 12:30:04

标签: mdx

嗨,我是mdx的新手, 我想结合使用mdx查询的两个select语句结果集(并排像union),请任何正文帮我解决这个问题 第一次查询:

 SELECT
{ [Last Year] }
ON COLUMNS,

 { {[Location].[Location].&[7], [Location].[Location].&[12], [Location].[Location].&[11],
[Location].[Location].&[19], [Location].[Location].&[17], [Location].[Location].&[16],
[Location].[Location].&[9], [Location].[Location].&[18] },{[Location].[Location].[All]}}
ON ROWS

FROM [Cube1]

WHERE ( [Measures].[Labour %] )

此处[去年]是一个计算集

[去年] =====

{STRTOMEMBER("[Date].[Month].&["+ cstr(year(now())-2) +"-11-01T00:00:00]"):
        (STRTOMEMBER("[Date].[Month].&["+ cstr(year(now())-1) +"-10-01T00:00:00]"))}

第二次查询:

WITH MEMBER [Measures].[Budget ] AS IIF(avg([Last Year],IIF(([Measures].[Budget]>0),[Measures].[Budget],null)),
                                        avg([Last Year],IIF(([Measures].[Budget]>0),[Measures].[Budget],null)),0.00),

MEMBER [Measures].[YTD] AS IIF(avg([Last Year], IIF(([Measures].[Labour %]>0),[Measures].[Labour %],null))<>null,
                              avg([Last Year], IIF(([Measures].[Labour %]>0),[Measures].[Labour %],null)),0.00),
FORMAT_STRING = "Standard",
BACK_COLOR = CASE WHEN [YTD] = 0  THEN /*White*/16777215 /*White*/  
WHEN [YTD] <= [Measures].[Budget ] THEN 65408
     WHEN [YTD]<= [Measures].[Budget ] +5 THEN 65535
     WHEN [YTD]> [Measures].[Budget ] +5 THEN 255
END,
VISIBLE = 1
SELECT
{  [Measures].[YTD], [Measures].[Budget ] }
ON COLUMNS,

{ { [Location].[Location].&[7], [Location].[Location].&[12], [Location].[Location].&[11], [Location].[Location].&[19], [Location].[Location].&[17], [Location].[Location].&[16], [Location].[Location].&[9], [Location].[Location].&[18] },{[Location].[Location].[All]} }
ON ROWS

FROM [Cube1]

**这里==&gt; [措施]。[YTD],[措施]。[预算]是计算成员 我想要像

中的结果

coulmns ===&GT; ytd,预算,nov,dec,jan,feb。,,,,,,,,,,十月和行====&gt;地点和总数(所有地点的平均值)

请指导我获得像mdx查询**

的解决方案

1 个答案:

答案 0 :(得分:0)

你的“UNION”概念不会有两个主要原因:

1。您不能使用来自不同层次结构的UNION成员。 2。查询结构不同。

只能“并排”看待它们,就是在两个不同的窗口中打开查询。

相反,如果您只想查看度量和成员的组合视图,请使用以下任一查询:

//Go for this if you want to see the Locations in output

WITH MEMBER [Measures].[Budget ] AS IIF(avg([Last Year],IIF(([Measures].[Budget]>0),[Measures].[Budget],null)),
                                        avg([Last Year],IIF(([Measures].[Budget]>0),[Measures].[Budget],null)),0.00),

MEMBER [Measures].[YTD] AS IIF(avg([Last Year], IIF(([Measures].[Labour %]>0),[Measures].[Labour %],null))<>null,
                              avg([Last Year], IIF(([Measures].[Labour %]>0),[Measures].[Labour %],null)),0.00),
FORMAT_STRING = "Standard",
BACK_COLOR = CASE WHEN [YTD] = 0  THEN /*White*/16777215 /*White*/  
WHEN [YTD] <= [Measures].[Budget ] THEN 65408
     WHEN [YTD]<= [Measures].[Budget ] +5 THEN 65535
     WHEN [YTD]> [Measures].[Budget ] +5 THEN 255
END,
VISIBLE = 1


SELECT
{  [Measures].[YTD], [Measures].[Budget ], [Measures].[Labour %] }
ON COLUMNS,
{ [Last Year] }
*
{ { [Location].[Location].&[7], 
[Location].[Location].&[12], 
[Location].[Location].&[11], 
[Location].[Location].&[19], 
[Location].[Location].&[17], 
[Location].[Location].&[16], 
[Location].[Location].&[9], 
[Location].[Location].&[18] },
{[Location].[Location].[All]} }
ON ROWS
FROM [Cube1]

OR

//A cleaner one. Go for this if you don't want to see the Locations in output

WITH MEMBER [Measures].[Budget ] AS IIF(avg([Last Year],IIF(([Measures].[Budget]>0),[Measures].[Budget],null)),
                                        avg([Last Year],IIF(([Measures].[Budget]>0),[Measures].[Budget],null)),0.00),

MEMBER [Measures].[YTD] AS IIF(avg([Last Year], IIF(([Measures].[Labour %]>0),[Measures].[Labour %],null))<>null,
                              avg([Last Year], IIF(([Measures].[Labour %]>0),[Measures].[Labour %],null)),0.00),
FORMAT_STRING = "Standard",
BACK_COLOR = CASE WHEN [YTD] = 0  THEN /*White*/16777215 /*White*/  
WHEN [YTD] <= [Measures].[Budget ] THEN 65408
     WHEN [YTD]<= [Measures].[Budget ] +5 THEN 65535
     WHEN [YTD]> [Measures].[Budget ] +5 THEN 255
END,
VISIBLE = 1


SELECT
{  [Measures].[YTD], [Measures].[Budget ], [Measures].[Labour %] }
ON COLUMNS,
{ [Last Year] } ON ROWS
FROM [Cube1]
WHERE
{ { [Location].[Location].&[7], 
[Location].[Location].&[12], 
[Location].[Location].&[11], 
[Location].[Location].&[19], 
[Location].[Location].&[17], 
[Location].[Location].&[16], 
[Location].[Location].&[9], 
[Location].[Location].&[18] },
{[Location].[Location].[All]} }