Search code examples
attributesfilteringmdx

how to filter new clients in mdx based on a date-attribute?


I am fairly new to MDX and I want to filter all of the new clients from the Client-dimension showing the number of their transactions. I use the code below. Syntactically OK but not returning the 1931 clients I am searching for but It returns an empty set.

select 
    {[Measures].[Transaction Count]} on columns
,   filter([Client].[Client ID],[Client].[Date Birth] >= '2016-01-01') on rows 
from [Transactions];

Your second query is the following:

SELECT 
  NON EMPTY { [Measures].[Transaction Count] } ON COLUMNS
, NON EMPTY { ([Client].[Client ID].[Client ID].ALLMEMBERS ) } 
    DIMENSION PROPERTIES 
       MEMBER_CAPTION
     , MEMBER_UNIQUE_NAME ON ROWS 
 FROM ( 
    SELECT 
     ( Filter( 
         [Client].[Date Birth].[Date Birth].ALLMEMBERS
       , Instr( [Client].[Date Birth].currentmember.Properties( 'Member_Caption' ), '2016' ) = 1 ) ) ON COLUMNS 
    FROM [DW3_Summary]
 ) 
  CELL PROPERTIES VALUE

Solution

  • This is the problem [Client].[Date Birth] >= '2016-01-01' as you have a member type on the left of the operator >= and a date type on the right side.

    I think you could create a measure that is the value of the Date Birth hierarchy, then try filtering on that:

    WITH MEMBER [Measures].[DateBirthValue] AS
      [Client].[Date Birth].CURRENTMEMBER.MEMBERVALUE
    SELECT 
        [Measures].[Transaction Count] ON 0
    ,   FILTER(
           [Client].[Client ID].MEMBERS
          ,[Measures].[DateBirthValue] >= '2016-01-01'
        ) ON 1
    FROM [Transactions];
    

    Unfortunately I do not have access to the AdvWrks cube to test the above, so fingers crossed!

    SELECT 
      NON EMPTY [Measures].[Transaction Count] ON 0
    , NON EMPTY [Client].[Client ID].[Client ID].ALLMEMBERS 
        ON ROWS 
     FROM 
       ( 
        SELECT 
             [Client].[Date Birth].[Date Birth].&[2016-01-01] 
            :
             NULL 
           ON 0 
        FROM [DW3_Summary]
       );