问题
I would like to show outcome of these 2 queries in one table.
SELECT
{[Measures].[Udzial Wieznia w Aktywnosci Count]} ON COLUMNS,
{[Aktywnosc].[Id Wiezienia].Members} ON ROWS
FROM [Wiezienia HD2]
WHERE [Udzial Wieznia w Aktywnosci].[Id Ucieczki].[2] : [Udzial Wieznia w Aktywnosci].[Id Ucieczki].[101]
and
SELECT
{[Measures].[Udzial Wieznia w Aktywnosci Count]} ON COLUMNS,
{[Aktywnosc].[Id Wiezienia].Members} ON ROWS
FROM [Wiezienia HD2]
First one shows how many escapes from jail there were in each jail, and second one show how many people are in each jail.
回答1:
This is the suggestion of Aaron West ported over to AdvWrks
:
SELECT
{
[Measures].[Internet Sales Amount]
,Aggregate
(
[Date].[Calendar].[Calendar Year].&[2006]
: [![enter image description here][1]][1]
[Date].[Calendar].[Calendar Year].&[2007]
,[Measures].[Internet Sales Amount]
)
} ON 0
,[Product].[Category].[Category] ON 1
FROM [Adventure Works];
As pointed out by Greg Galloway it errors:
Query (2, 3) The function expects a tuple set expression for the 2 argument. A string or numeric expression was used.
If we move the calculation to a WITH
statement:
WITH
MEMBER [Measures].[SalesIn2006/2007] AS
Aggregate
(
[Date].[Calendar].[Calendar Year].&[2006]
:
[Date].[Calendar].[Calendar Year].&[2007]
,[Measures].[Internet Sales Amount]
)
SELECT
{
[Measures].[Internet Sales Amount]
,[Measures].[SalesIn2006/2007]
} ON 0
,[Product].[Category].[Category] ON 1
FROM [Adventure Works];
We now get a result:
So against your cube it'll probably look a little like this:
WITH
MEMBER [Measures].[Count freeAtLast] AS
Aggregate
(
[Udzial Wieznia w Aktywnosci].[Id Ucieczki].[2]
:
[Udzial Wieznia w Aktywnosci].[Id Ucieczki].[101]
,[Measures].[Udzial Wieznia w Aktywnosci Count]
)
SELECT
{
[Measures].[Udzial Wieznia w Aktywnosci Count]
,[Measures].[Count freeAtLast]
} ON 0
,[Aktywnosc].[Id Wiezienia].MEMBERS ON 1
FROM [Wiezienia HD2];
回答2:
WITH MEMBER [Measures].x AS
AGGREGATE( [Udzial Wieznia w Aktywnosci].[Id Ucieczki].[2]
: [Udzial Wieznia w Aktywnosci].[Id Ucieczki].[101]
, [Measures].[Udzial Wieznia w Aktywnosci Count] )
SELECT { [Measures].[Udzial Wieznia w Aktywnosci Count]
, Measures.x
} ON COLUMNS
, [Aktywnosc].[Id Wiezienia].Members ON ROWS
FROM [Wiezienia HD2]
If AGGREGATE doesn't work, try SUM. By the way, be careful that the OrderBy is set to KeyColumn (which should be a numeric datatype) on that attribute that is 2 to 101, or your range won't work correctly.
Edit: Perhaps my incorrect first answer put the Aggregate inline because I was thinking of the fact that a tuple set expression can act a little like a SUM, if you have a single hierarchy member to tuple with. Eg, if you created a dimension attribute for the range 2 to 101, you could use an expression like this:
( [Udzial Wieznia w Aktywnosci].[new attribute name].[2_to_101]
, [Measures].[Udzial Wieznia w Aktywnosci Count] )
But then you would need to ensure that the dimensionality of the tuples is the same in all members on the axis, eg:
SELECT { ( [Udzial Wieznia w Aktywnosci].[new attribute name].[2_to_101]
, [Measures].[Udzial Wieznia w Aktywnosci Count] )
( [Udzial Wieznia w Aktywnosci].[new attribute name].[All]
, [Measures].[Udzial Wieznia w Aktywnosci Count] )
} ON COLUMNS
, [Aktywnosc].[Id Wiezienia].Members ON ROWS
FROM [Wiezienia HD2]
来源:https://stackoverflow.com/questions/34232013/merge-2-mdx-queries