1

有人可以帮我解决以下 MDX 问题:我得到了如下数据集:

 With
Set Range1 as {[Date].[Calendar].[Month].&[2008]&[1]
:[Date].[Calendar].[Month].&[2008]&[12]}

Set Range2 as 
{[Delivery Date].[Calendar].[Month].&[2008]&[1]:
[Delivery Date].[Calendar].[Month].&[2008]&[12]}

MEMBER measures.A as [Measures].[Internet Order Count] + [Measures].[Reseller Order Count]
select {[Measures].[Internet Order Count],A} on columns,
non empty(
[Sales Territory].[Sales Territory Country].[Sales Territory Country]*

Range1
*Range2
)
having [Date].[Calendar].currentmember.member_caption
= [Delivery Date].[Calendar].currentmember.member_caption
AND A > 100 
on rows 
from [Adventure Works]

问题是结果是用 [Sales Territory] ​​维度显示的 - 我想得到只显示月份的结果,但度量 A 也根据 [Sales Territory] ​​计算。

度量 A 的结果应如下所示:

例如:一月的 1128

正确的结果应如下所示: 在此处输入图像描述

谢谢

抱歉 - 无法通过代码: 在此处输入图像描述

4

4 回答 4

1
WITH MEMBER [Measures].[A] AS
   [Measures].[Internet Order Count] + [Measures].[Reseller Order Count]
SELECT
{ [Measures].[Internet Order Count], [Measures].[A] } ON COLUMNS,
 [Date].[Calendar].[Month] ON ROWS
 FROM (
   SELECT { [Measures].[Internet Order Count] } ON COLUMNS,
   Filter (
     Filter ( [Date].[Calendar].[Month] * [Delivery Date].[Calendar].[Month], [Date].[Calendar].CurrentMember.Name = [Delivery Date].[Calendar].CurrentMember.Name ) * [Sales Territory].[Sales Territory Country].[Sales Territory Country],
     [Measures].[Internet Order Count] + [Measures].[Reseller Order Count] > 100
   ) ON ROWS
   FROM [Adventure Works]
 )
WHERE [Date].[Calendar Year].[CY 2008]
于 2014-10-28T23:25:21.070 回答
1

我暂时忽略了范围,但这是我能得到的最接近的:

WITH 
  MEMBER measures.c1 AS 
    [Date].[Calendar].CurrentMember.Member_Caption 
  MEMBER measures.c2 AS 
    [Delivery Date].[Calendar].CurrentMember.Member_Caption 
  MEMBER measures.x AS 
    IIF
    (
      measures.c1 = measures.c2
     ,
      [Measures].[Internet Order Count] + [Measures].[Reseller Order Count]
     ,null
    ) 
  SET q AS 
    Filter
    (
        [Sales Territory].[Sales Territory Country].[Sales Territory Country]*
        [Date].[Calendar].[Month].MEMBERS*
        [Delivery Date].[Calendar].[Month].MEMBERS
     ,
      measures.x > 100
    ) 
SELECT 
  {measures.x} ON 0
 ,NON EMPTY 
    Extract
    (
      q
     ,[Date].[Calendar]
     ,[Delivery Date].[Calendar]
    ) ON 1
FROM [Adventure Works];

编辑

以下为行提供了两个选项 - 选项 A 和选项 B:

WITH 
  MEMBER measures.c1 AS 
    [Date].[Calendar].CurrentMember.Member_Caption 
  MEMBER measures.c2 AS 
    [Delivery Date].[Calendar].CurrentMember.Member_Caption 
  MEMBER measures.x AS 
    IIF
    (
      measures.c1 = measures.c2
     ,
      [Measures].[Internet Order Count] + [Measures].[Reseller Order Count]
     ,null
    ) 
  SET q AS 
    Filter
    (
        [Sales Territory].[Sales Territory Country].[Sales Territory Country]*
        [Date].[Calendar].[Month].&[2008]&[1]*
        [Delivery Date].[Calendar].[Month].MEMBERS
     ,
      measures.x > 100
    ) 
SELECT 
  {measures.x} ON 0

//<<<<<Option A.try just this and sum the cells ....1128 
 ,q  

//<<<<<Option B.try just this and sum the cells ....1221
//,Extract
//    (
//      q
//     ,[Date].[Calendar]
//     ,[Delivery Date].[Calendar]
//    ) 

ON 1
FROM [Adventure Works];

编辑 2

这给出了正确的答案 - 我的意思是不要引用真正的作者:https ://social.msdn.microsoft.com/Forums/en-US/be750f75-0e39-41b8-9578-9dceb58a5865/strange-context-aware -behaviour-of-adventure-works-script?forum=sqlanalysisservices

WITH 
  MEMBER measures.c1 AS 
    [Date].[Calendar].CurrentMember.Member_Caption 
  MEMBER measures.c2 AS 
    [Delivery Date].[Calendar].CurrentMember.Member_Caption 
  MEMBER measures.[Calendar Month] AS 
    measures.c1 
  MEMBER measures.[Delivery Month] AS 
    measures.c2 
  MEMBER measures.x AS 
    IIF
    (
      measures.c1 = measures.c2
     ,
      [Measures].[Internet Order Count] + [Measures].[Reseller Order Count]
     ,NULL
    ) 
SELECT 
  {
    measures.[Calendar Month]
   ,measures.[Delivery Month]
   ,measures.x
  } ON COLUMNS
FROM [Adventure Works]
WHERE 
    {
      NonEmpty
      (
          [Sales Territory].[Sales Territory].[Country].MEMBERS*
          [Date].[Calendar].[Month].&[2008]&[1]*
          [Delivery Date].[Calendar].[Month].MEMBERS
       ,measures.x
      )
    }
  - 
    {
      Filter
      (
        NonEmpty
        (
            [Sales Territory].[Sales Territory].[Country].MEMBERS*
            [Date].[Calendar].[Month].&[2008]&[1]*
            [Delivery Date].[Calendar].[Month].MEMBERS
         ,measures.x
        )
       ,
        measures.x < 100
      )
    };
于 2014-10-27T15:53:01.913 回答
0

如果不想 [Sales Territory].[Sales Territory Country].[Sales Territory Country]在 final中看到SELECT,可以使用EXISTSMDX 中的子句

 With
Set Range1 as {[Date].[Calendar].[Month].&[2008]&[1]
:[Date].[Calendar].[Month].&[2008]&[12]}

Set Range2 as 
{[Delivery Date].[Calendar].[Month].&[2008]&[1]:
[Delivery Date].[Calendar].[Month].&[2008]&[12]}

MEMBER measures.A as [Measures].[Internet Order Count] + [Measures].[Reseller Order Count]

select {[Measures].[Internet Order Count],A} on columns,
non empty filter((
exists({Range1
*Range2}, [Sales Territory].[Sales Territory Country].[Sales Territory Country]
)), measures.A > 100)
having [Date].[Calendar].currentmember.member_caption
= [Delivery Date].[Calendar].currentmember.member_caption
于 2014-10-27T16:23:03.353 回答
0

您可以使用销售区域进行过滤,方法是执行以下操作而不是您当前的from [Adventure Works]

from (
    select {[Sales Territory].[Sales Territory Country].[Sales Territory Country]} on columns
    from [Adventure Works]
)

话虽如此,然后您可以从此处删除销售区域..然后就可以了Range1 * Range2

non empty(
[Sales Territory].[Sales Territory Country].[Sales Territory Country] 
Range1
*Range2
)

然后,您可以使用 MDX过滤器功能继续过滤

from (
    select {[Sales Territory].[Sales Territory Country].[Sales Territory Country]} on columns
    from
        ( 
            select { 
                FILTER (
                                         [Date].[Calendar].MEMBERS
                                        ,[Date].[Calendar].currentmember.member_caption = [Delivery Date].[Calendar].currentmember.member_caption and A > 100
                       )
            } on columns
            [Adventure Works]
        )
)
于 2014-10-27T14:03:12.933 回答