MDX Builder - 使用INSTR函数进行过滤

时间:2017-07-26 07:44:55

标签: select mdx

我是MDX的全新人物。我需要过滤包含子串“SBP1”的所有记录。当我像这样单独输入每条记录时,它对我有用: {[Article].[Article Alternative ID CPG].[SBP1 0],[Article].[Article Alternative ID CPG].[SBP1 1],[Article].[Article Alternative ID CPG].[SBP1 W]}

MDX builder screenshot

工作代码:

SELECT 
  NON EMPTY 
    {[Measures].[Value]} ON COLUMNS
 ,NON EMPTY 
    {
        [Article].[Article Alternative ID CPG].[Article Alternative ID CPG].ALLMEMBERS*
        [Article].[Market].[Market].ALLMEMBERS*
        [Article].[Brand].[Brand].ALLMEMBERS*
        [Article].[Product].[Product].ALLMEMBERS
    }
  DIMENSION PROPERTIES 
    MEMBER_CAPTION
   ,MEMBER_UNIQUE_NAME
   ON ROWS
FROM 
(
  SELECT 
    {
      [Article].[Article Alternative ID CPG].[SBP1  0]
     ,[Article].[Article Alternative ID CPG].[SBP1  1]
     ,[Article].[Article Alternative ID CPG].[SBP1  W]
    } ON COLUMNS
  FROM 
  (
    SELECT 
      {[Measure Data Type].[Data Type].[Actuals]} ON COLUMNS
    FROM 
    (
      SELECT 
        {[Org Sales Area].[Sales Organization Key].[DEB1]} ON COLUMNS
      FROM 
      (
        SELECT 
          {[Org Sales Area].[Distribution Channel].&[DO]} ON COLUMNS
        FROM 
        (
          SELECT 
            {[Org Business Unit].[Business Unit].[U-K]} ON COLUMNS
          FROM 
          (
            SELECT 
              {[Measure Item].[Measure Item].&[KF00310]} ON COLUMNS
            FROM 
            (
              SELECT 
                {[Date of Posting].[Posting Y Q M D].[Posting Year].&[2017]} ON COLUMNS
              FROM [COLOR LEAN CPG]
            )
          )
        )
      )
    )
  )
)
WHERE 
  (
    [Date of Posting].[Posting Y Q M D].[Posting Year].&[2017]
   ,[Measure Item].[Measure Item].&[KF00310]
   ,[Org Business Unit].[Business Unit].[U-K]
   ,[Org Sales Area].[Distribution Channel].&[DO]
   ,[Org Sales Area].[Sales Organization Key].[DEB1]
   ,[Measure Data Type].[Data Type].[Actuals]
  )
CELL PROPERTIES 
  VALUE
 ,BACK_COLOR
 ,FORE_COLOR
 ,FORMATTED_VALUE
 ,FORMAT_STRING
 ,FONT_NAME
 ,FONT_SIZE
 ,FONT_FLAG;

如何使用instr函数提高效率? 我试过这个但是不起作用:

SELECT 
  [Measures].[Value] ON COLUMNS
 ,Filter
  (
    [Article].[Article Alternative ID CPG].[Article Alternative ID CPG].ALLMEMBERS
   ,
      Instr
      (
        [Article].[Article Alternative ID CPG].[Article Alternative ID CPG].CurrentMember.Name
       ,'SBP1'
      )
    > 0
  ) ON ROWS
FROM [COLOR LEAN CPG];

我的MDX statament有什么问题? MDX with my SELECT screenshot 谢谢

2 个答案:

答案 0 :(得分:0)

我认为在应用CURRENTMEMBER功能时你可能已经导航了一点。试试这个:

SELECT 
  [Measures].[Value] ON COLUMNS
 ,Filter
  (
    [Article].[Article Alternative ID CPG].[Article Alternative ID CPG].ALLMEMBERS
   ,
      Instr
      (
        [Article].[Article Alternative ID CPG].CurrentMember.Name   //<<[Article].[Article Alternative ID CPG].[Article Alternative ID CPG].CurrentMember.Name
       ,'SBP1'
      )
    > 0
  ) ON ROWS
FROM [COLOR LEAN CPG];

希望名字适合您,但我通常会选择MEMBERCAPTION

SELECT 
  [Measures].[Value] ON COLUMNS
 ,Filter
  (
    [Article].[Article Alternative ID CPG].[Article Alternative ID CPG].ALLMEMBERS
   ,
      Instr
      (
        [Article].[Article Alternative ID CPG].CurrentMember.MEMBERCAPTION
       ,'SBP1'
      )
    > 0
  ) ON ROWS
FROM [COLOR LEAN CPG];

答案 1 :(得分:0)

我找到了一个有效的MDX声明: Filter( [Article].[Main Article Alternative ID CPG].[Main Article Alternative ID CPG].ALLMEMBERS,Instr( [Article].[Main Article Alternative ID CPG].currentmember.Properties( 'Member_Caption' ), 'SBP1' ) > 0)

但是我不知道这个解决方案转换为纯GUI MDX BUILDER并将其插入那里。