2017-07-26 52 views
0

我是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 - 使用INSTR功能進行過濾

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 謝謝

回答

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]; 
+0

謝謝您的回覆,但它似乎仍然是錯誤的(我試過MEMBERCAPTION和CurrentMember.Name):SELECT [Measures]。[Value] ON COLUMNS, Filter([Article]。[Article Alternative ID CPG] [文章備選ID CPG] .ALLMEMBERS, Instr([Article Article。[Article Alternative ID CPG] .CurrentMember.MEMBERCAPTION,'SBP1')> 0)ON ROWS FROM [COLOUR LEAN CPG]; – kabarto

+0

「謝謝你的回覆,但它似乎仍然是錯誤的......」如果我的回答太錯誤,那麼你的解決方案如何使用「[文章] [文章替代ID CPG] .CurrentMember」?嘗試與您的原始實施! (這不會起作用)[文章] [文章替代ID CPG] [文章替代ID CPG] .CurrentMember') – whytheq

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中插入它。

+0

這就是我說'我認爲你可能導航了一點點,當應用CURRENTMEMBER函數'在我的回答...這是你的腳本 – whytheq

+0

的主要問題這是什麼意思? '但是這個解決方案我不知道要轉換成純粹的GUI MDX BUILDER插入它。「 – whytheq