MDX选择测量计数,其中测量> 0

时间:2014-10-23 10:53:01

标签: ssas mdx cube olap-cube

我想计算数量 上的不同(维度)USER GUID 特别(维度)月 其中(测量)M1> 0和(测量)M2> 0

我的查询:

 WITH 
  MEMBER [Measures].[M1 Count] AS 
    Count
    (
      NonEmpty
      (
          NonEmpty
          (
            [AAUser].[USER GUID].[USER GUID].MEMBERS
           ,[Measures].[M1]
          )
        * 
          {[Measures].[M1]}
      )
    ) 
  MEMBER [Measures].[T2 Count] AS 
    Count
    (
      NonEmpty
      (
        NonEmpty
        (
          [AAUser].[USER GUID].[USER GUID].MEMBERS
         ,[Measures].[T2]
        )
       ,{[Measures].[T2]}
      )
    ) 
SELECT 
  {
    [Measures].[M1 Count]
   ,[Measures].[T2 Count]
  } ON COLUMNS
 ,[AATime].[Month].[Month].ALLMEMBERS ON ROWS
FROM [MyCube]
WHERE 
  {
      StrToMember("[AATime].&[2013-11-01T00:00:00]")
    : 
      StrToMember("[AATime].&[2014-10-31T00:00:00]")
  };

我得到的结果是:
enter image description here

这是错误的,因为我选择了NONEMPTY,它会返回所有内容(即使值为0)。任何人都可以修改我的查询并过滤(where [Measures].[M1] > 0 and [Measures].[M2] > 0)

1 个答案:

答案 0 :(得分:2)

(未经测试)也许您可以使用函数filter

WITH 
  MEMBER [Measures].[M1 Count] AS 
    Count
    (
      NonEmpty
      (
          NonEmpty
          (
            filter(
              [AAUser].[USER GUID].[USER GUID].MEMBERS
              , ([Measures].[M1] > 0 AND [Measures].[M2] > 0)
            )
           ,[Measures].[M1]
          )
        * 
          {[Measures].[M1]}
      )
    ) 
  MEMBER [Measures].[T2 Count] AS 
    Count
    (
      NonEmpty
      (
        NonEmpty
        (
            filter(
              [AAUser].[USER GUID].[USER GUID].MEMBERS
              , ([Measures].[M1] > 0 AND [Measures].[M2] > 0)
            )          
         ,[Measures].[T2]
        )
       ,{[Measures].[T2]}
      )
    ) 
SELECT 
  {
    [Measures].[M1 Count]
   ,[Measures].[T2 Count]
  } ON COLUMNS
 ,[AATime].[Month].[Month].ALLMEMBERS ON ROWS
FROM [MyCube]

但也许这些方面的东西会更好用吗?

WITH 
  MEMBER [Measures].[M1 Count] AS 
    Sum
    (
      [AAUser].[USER GUID].[USER GUID]
     ,IIF
      (
        [Measures].[M1] > 0 AND [Measures].[M2] > 0
       ,1
       ,NULL
      )
    ) 
  MEMBER [Measures].[T2 Count] AS 
    Sum
    (
      NonEmpty
      (
        [AAUser].[USER GUID].[USER GUID]
       ,[Measures].[T2]
      )
     ,IIF
      (
        [Measures].[M1] > 0 AND [Measures].[M2] > 0
       ,1
       ,NULL
      )
    ) 
SELECT 
  {
    [Measures].[M1 Count]
   ,[Measures].[T2 Count]
  } ON COLUMNS
 ,[AATime].[Month].[Month].ALLMEMBERS ON ROWS
FROM [MyCube];