MDX:加入月份总数

MDX: Joining months with total

我想这样创建 table:

      [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]

但是如何将它们连接起来或写成一个?

您可以像这样扩展 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];

结果如下,这似乎是合理的:

尝试将您的第一个查询更改为:

SELECT
[Time].[Month].Members ON COLUMNS,
TOPCOUNT([Items], 5, [Count]) ON ROWS
FROM [Cube]
WHERE([Time].[Year].[Year].&[2015-01-01T00:00:00])