我想创建这样的表:
[January] [February] ...other months... [Total for Year]
item1
item2
item3
很容易创建2个不同的查询,数月和总数,如下所示:
SELECT
[Time].[Month].[Month] ON COLUMNS,
TOPCOUNT([Items], 5, [Count]) ON ROWS
FROM [Cube]
WHERE([Time].[Year].[Year].&[2015-01-01T00:00:00])
和
WITH
MEMBER [Total] AS SUM([Count], [Time].[Year].[Year].&[2015-01-01T00:00:00])
SELECT
[Total] ON COLUMNS,
TOPCOUNT([Items], 5, [Count]) ON ROWS
FROM [Cube]
但如何连接它们或编写单个?
答案 0 :(得分:0)
您可以像这样展开WITH
语句:
WITH
MEMBER [Time].[Month].[All].[Total] AS --<<THIS IS HOSTED IN SAME HIERARCHY AS THE SET THAT FOLLOWS
Sum
(
[Count]
,[Time].[Year].[Year].&[2015-01-01T00:00:00]
)
SET [mths] AS
Exists
(
[Time].[Month].[Month].MEMBERS
,[Time].[Year].[Year].&[2015-01-01T00:00:00]
)
SET [concatenatet_set] AS
{
--<<THE FOLLOWING CAN BE BROUGHT TOGETHER AS THEY HAVE THE SAME "DIMENSIONALITY" I.E. FROM THE SAME HIERARCHY
[mths]
,[Time].[Month].[All].[Total]
}
SELECT
[concatenatet_set] ON COLUMNS
,TopCount
(
[Items]
,5
,[Count]
) ON ROWS
FROM [Cube];
以下是我用来测试针对AdvWrks
的上述想法的脚本:
WITH
MEMBER [Date].[Calendar].[All].[Total] AS
Sum
(
[Measures].[Internet Sales Amount]
,(
[Date].[Calendar].[All Periods]
,[Date].[Calendar Year].&[2007]
,[Date].[Calendar Quarter of Year].&[CY Q1]
)
)
SET [mths] AS
Exists
(
[Date].[Calendar].[Month]
,(
[Date].[Calendar Year].&[2007]
,[Date].[Calendar Quarter of Year].&[CY Q1]
)
)
SET [concatenatet_set] AS
{
[mths]
,[Date].[Calendar].[All].[Total]
}
SELECT
[concatenatet_set] ON COLUMNS
,TopCount
(
NonEmpty
(
[Product].[Subcategory].[Subcategory]
,(
[Date].[Calendar Year].&[2007]
,[Date].[Calendar Quarter of Year].&[CY Q1]
)
)
,5
,[Measures].[Internet Sales Amount]
) ON ROWS
FROM [Adventure Works]
WHERE
[Measures].[Internet Sales Amount];
这导致以下似乎是合理的:
答案 1 :(得分:0)
尝试将您的第一个查询更改为:
SELECT
[Time].[Month].Members ON COLUMNS,
TOPCOUNT([Items], 5, [Count]) ON ROWS
FROM [Cube]
WHERE([Time].[Year].[Year].&[2015-01-01T00:00:00])