Search code examples
subqueryssasmdx

MDX issue, rows count using a subquery


I am trying to count rows(Postal codes per State) using a sub query... Please help me to understand the following behavior. MDX:

WITH
SET [rows] AS
  {[Customer].[Postal Code].members} 
MEMBER [Measures].[RowsCount] AS
  Count
    (
      [rows]
    )
MEMBER [Measures].[RowsCount1] AS 
  Count
    (
      {[Customer].[Postal Code].members}
    )
SELECT
  {
    [Measures].[RowsCount]
    ,[Measures].[RowsCount1]
  } ON columns
FROM
  (
    SELECT
      (
        {[Customer].[State Province Name].&[Hamburg]}
      ) ON Columns
   FROM [Analysis Services Tutorial]
  )
  1. Why [Measures].[RowsCount] and [Measures].[RowsCount1] return different results although both use the same set: "{[Customer].[Postal Code].members}")?
  2. Only [Measures].[RowsCount] returns a correct/expected result, but my goal is to avoid the "WITH SET" definition, and use only the [Measures].[RowsCount1] inline, which should return a correct result.

EDIT

The following statement would be a solution:

MEMBER [Measures].[RowsCount1] AS 
  Count
    (
      {[Customer].[Postal Code].members} * {[Customer].[State Province Name].&[Hamburg]}
    )

however I would like to achieve it by using a CurrentMember function, something like this (does not work):

MEMBER [Measures].[RowsCount1] AS 
  Count
    (
      {[Customer].[Postal Code].members} * {[Customer].[State Province Name].CurrentMember}
    )

Solution

  • A SUBSELECT in mdx isn't the same as a SUBQUERY in sql - its not always a full filter in the way a subquery is - hence the difference in your results.

    But using AdvWrks I'm having difficulty replicating the behaviour you're reporting.

    I suspect you could amend your script to one of the following to get your desired result

     MEMBER [Measures].[RowsCount1] AS 
        Count
        (
            [DIM bla].[HIER bla].[Level]
          * 
            {[DIM bla2].[HIER bla2].&[test]}
        ) 
    

    Or instead of test use the All member:

      MEMBER [Measures].[RowsCount1] AS 
        Count
        (
            [DIM bla].[HIER bla].[Level]
          * 
            {[DIM bla2].[HIER bla2].[All]}
        )