WHERE子句中的MDX计算成员会导致不同的结果

时间:2015-04-08 17:21:35

标签: ssas mdx

以下查询具有不同的结果集,具体取决于我在WHERE子句中使用的[Measures]。 使用[Measures]。[MetricFormula]而不是[Measures]。[Actual]激活,查询会提供不同的(和预期的)结果。

WITH
MEMBER [Measures].[MetricFormula] AS Measures.[Downloads]
MEMBER [Measures].[Actual] AS [Measures].[MetricFormula], LANGUAGE = 1031,FORMAT_STRING='#,##0'

SET [mySet] as 
topcount(
    nonempty(
        filter(
            distinct descendants({[AppPackages].[AppPackages].&[F_TAAM00000069]}), 
            [Measures].[MetricFormula] <> 0 AND ([AppPackages].[AppPackages].PROPERTIES('AppTypeID') = 'DETAIL')
            ),
        [Time].[Calendar].[Date].&[2015-03-22T00:00:00]:[Time].[Calendar].[Date].&[2015-03-31T00:00:00]
        )
    ,6
    ,aggregate([Time].[Calendar].[Date].&[2015-03-22T00:00:00]:[Time].[Calendar].[Date].&[2015-03-31T00:00:00], [Measures].[MetricFormula]))


select
([Time].[Calendar].[Date].&[2015-03-22T00:00:00]:[Time].[Calendar].[Date].&[2015-03-31T00:00:00]) ON COLUMNS,
([mySet]) ON ROWS   

FROM [Facts] 
WHERE (
--([Measures].[MetricFormula]),
([Measures].[Actual]),
{[DownloadTypes].[DownloadTypes].&[New]}
)

([Measures]。[Downloads]是多维数据集中定义的真实度量。)

问题:为什么它会产生不同的结果? 我使用此构造(以各种形式)来简化基于代码的查询生成。 在开始重新编写查询生成器之前,我想了解不同之处。

背景: 该查询应该根据给定的度量计算给定时间范围内给定AppPackage的前6个后代。我首先找到时间范围的(非空)后代,我在其上添加topcount,确保时间聚合度量值驱动顶部计算。最后,我将评估集放在行上,时间放在列上,指定要查看的内容。除了描述的效果外,它的效果很好。

1 个答案:

答案 0 :(得分:1)

我很高兴在AdvWrks复制,但现在是:

WITH 
  MEMBER [Measures].[x] AS 
    [Measures].[Internet Order Count] 
  MEMBER [Measures].[y] AS 
    [Measures].[x] 
   ,LANGUAGE = 1031 
   ,FORMAT_STRING = '#,##0' 
  SET [s] AS 
    TopCount
    (
      NonEmpty
      (
        Filter
        (
          [State-Province].[State-Province].MEMBERS
         ,
          [Measures].[x] <> 0
        )
       ,
          [Date].[Calendar].[Month].&[2005]&[10]
        : 
          [Date].[Calendar].[Month].&[2006]&[5]
      )
     ,10
     ,Aggregate
      (
          [Date].[Calendar].[Month].&[2005]&[10]
        : 
          [Date].[Calendar].[Month].&[2006]&[5]
       ,[Measures].[x]
      )
    ) 
SELECT 
  {
      [Date].[Calendar].[Month].&[2005]&[10]
    : 
      [Date].[Calendar].[Month].&[2006]&[5]
  } ON COLUMNS
 ,Order
  (
    [s]
   ,[State-Province].CurrentMember.Member_Caption
   ,basc
  ) ON ROWS
FROM [Adventure Works]
WHERE 
  (
    //([Measures].[x]),
    ([Measures].[y]),
   {[Product].[Product Categories].[Category].&[1]}
  );

它与您的脚本相同 - 如果我们更改为[x],那么南澳大利亚州将从结果集中消失。


编辑
至于为什么 - 我现在知道了!

MDX对你很好,即使脚本中有错误也不会出错:

Aggregate
      (
          [Date].[Calendar].[Month].&[2005]&[10]
        : 
          [Date].[Calendar].[Month].&[2006]&[5]
       ,[Measures].[x]  //<<this is not allowed so `mdx` is ignoring it!
      )

请尝试以下操作或尝试将Aggregate换成Sum

WITH 
  MEMBER [Measures].[MetricFormula] AS 
    Measures.[Downloads] 
  MEMBER [Measures].[Actual] AS 
    [Measures].[MetricFormula] 
   ,LANGUAGE = 1031 
   ,FORMAT_STRING = '#,##0' 
  SET [mySet] AS 
    TopCount
    (
      NonEmpty
      (
        Filter
        (
          (DISTINCT 
            Descendants({[AppPackages].[AppPackages].&[F_TAAM00000069]}))
         ,
            [Measures].[MetricFormula] <> 0
          AND 
            [AppPackages].[AppPackages].Properties('AppTypeID') = 'DETAIL'
        )
       ,
          [Time].[Calendar].[Date].&[2015-03-22T00:00:00]
        : 
          [Time].[Calendar].[Date].&[2015-03-31T00:00:00]
      )
     ,6
     ,Aggregate
      (
          [Time].[Calendar].[Date].&[2015-03-22T00:00:00]
        : 
          [Time].[Calendar].[Date].&[2015-03-31T00:00:00]
       ,Measures.[Downloads]   //<<<<<<<<<<<<moved away from using a calculated measure as they are not working as expected inside the function `AGGREGATE`
      )
    ) 
SELECT 
    [Time].[Calendar].[Date].&[2015-03-22T00:00:00]
  : 
    [Time].[Calendar].[Date].&[2015-03-31T00:00:00] ON COLUMNS
 ,[mySet] ON ROWS
FROM [Facts]
WHERE 
  (
    --([Measures].[MetricFormula]),
    [Measures].[Actual]
   ,{[DownloadTypes].[DownloadTypes].&[New]}
  );

为什么?

使用Aggregate函数中的自定义度量[Measures].[MetricFormula]似乎是非法的,但当你在TopCount mdx中作为第二个参数的一部分执行此操作时,只是忽略错误并使用默认度量在你的立方体中....非常类似于忽略该错误的引擎?!


将计算成员纳入总体功能时出现的错误示例:

WITH 
  MEMBER [Measures].[j] AS 
    [Measures].[Internet Order Count] 
  MEMBER [Measures].[x] AS 
    Aggregate
    (
        [Date].[Calendar].[Month].&[2005]&[10]
      : 
        [Date].[Calendar].[Month].&[2006]&[5]
     ,[Measures].[j]   //<<FEEDING "ILLEGAL" CALCULATED MEMBER INTO AGGREGATE FUNCTION
    ) 
SELECT 
  {[Measures].[x]} ON COLUMNS
 ,[State-Province].[State-Province].MEMBERS ON ROWS
FROM [Adventure Works];