2

我正在尝试为此处记录的 SSRS 报告创建数据集:

http://sqlblog.com/blogs/stacia_misner/archive/2010/10/08/29249.aspx

挑战在于我有多个度量值,我想将它们的数据包含在度量值列中,并且我想在 RowValue 列中包含度量值的名称。因此,以下查询仅返回度量“销售额”的数据:

with
member [Measures].[Measure] as [Measures].[Sales Amount]
member [Measures].[RowValue] as [Product].[Category].CurrentMember.Name
member [Measures].[ColumnValue] as [Date].[Calendar Year].CurrentMember.Name
select {[Measures].[Measure], [Measures].[RowValue], [Measures].[ColumnValue]} on columns,
non empty ([Product].[Category].[Category].Members, [Date].[Calendar Year].[Calendar Year].Members) on rows
from [Adventure Works]

我想要做的是运行以下类型的查询,但在上面的查询结构中返回数据,这将允许我将其插入 SSRS 报告矩阵:

WITH 
       MEMBER measures.SalesAmount AS [Measures].[Sales Amount]
       MEMBER measures.CustomerCount AS [Measures].[Customer Count]
       MEMBER measures.InternetFreightCost AS [Measures].[Internet Freight Cost]
SELECT [Date].[Calendar Year].[Calendar Year].Members ON COLUMNS, 
    {measures.SalesAmount,measures.CustomerCount,measures.InternetFreightCost} ON ROWS
FROM [Adventure Works]

是否有任何 MDX 忍者知道这是否可以通过 MDX 实现?

4

1 回答 1

0
with member [Geography].[City].[Sales Amount] as 1
     member [Geography].[City].[Customer Count] as 1
     member [Geography].[City].[Freight Cost] as 1
     member [Measures].[RowValue] as [Geography].[City].CurrentMember.Name
     member [Measures].[ColumnValue] as [Date].[Calendar Year].CurrentMember.Name
     member [Measures].[Measure] as 
            CASE
                WHEN [Geography].[City].CurrentMember IS [Geography].[City].[Sales Amount]
                     THEN ([Measures].[Internet Sales Amount], [Geography].[City].[All Geographies])
                WHEN [Geography].[City].CurrentMember IS [Geography].[City].[Customer Count]
                     THEN ([Measures].[Customer Count], [Geography].[City].[All Geographies])
                WHEN [Geography].[City].CurrentMember IS [Geography].[City].[Freight Cost]
                     THEN ([Measures].[Internet Freight Cost], [Geography].[City].[All Geographies])
            END

select {[Measures].[RowValue], [Measures].[ColumnValue], [Measures].[Measure]}
       on columns,
       { [Geography].[City].[Sales Amount], [Geography].[City].[Customer Count], [Geography].[City].[Freight Cost]}
         * 
       [Date].[Calendar Year].[Calendar Year].Members
       having [Measures].[Measure] <> null
       on rows
from [Adventure Works]

应该提供你想要的。我用作[Geography].[City]实用程序层次结构。这可以是查询中未使用的任何层次结构。我选择了这个,因为它与查询中使用的两个度量组无关,因此不太可能在任何查询中使用。一些多维数据集设计者在他们的多维数据集中创建一个或两个与任何度量值组无关的单成员虚拟维度,并且可以像这里一样使用,以便在它们上创建计算成员。

ReportingServices 查询的困难之一是度量必须始终位于列中,并且列中不得有其他层次结构。因此,如果我们想在行中拥有度量,我们必须将它们移动到另一个层次结构中。这分两步完成:首先,我们在实用程序层次结构上创建虚拟成员,然后将它们映射到定义CASE构造中所需的度量[Measures].[Measure],我们需要使用实用程序维度的默认成员(在大多数情况下所有成员)以获得与我用于虚拟值的 1 不同的东西。

最后:non empty不能与此构造一起正常工作,因为[Measures].[RowValue]并且[Measures].[ColumnValue]永远不会为空。因此我将其替换为HAVING,它可以查看行中的特定列值。

于 2013-10-10T16:10:27.687 回答