0
votes

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}
    )
2

2 Answers

0
votes

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]}
    ) 
0
votes

Seems the context is different if add a slice in the where clause and sub-query: you can get a reference by slicer-or-sub-cube. But still no idea why the [RowCount] and [RowCount1] return the diff value.

I did a test on adv cube with the similar case you faced by adding column axis below, hope it help you.

WITH MEMBER [Measures].[count product of bikes] AS
count(EXTRACT( [Product].[Product].[Product]* [Product].
[Category].CurrentMember, [Product].[Product]))

SELECT  
{
[Measures].[count product of bikes] 
} on 0
,{
tail([Product].[Category].MEMBERs).item(0).item(0)
} on 1
from (SELECT{[Product].[Category].[Category].[Bikes]} ON 0  FROM [Adventure Works])

With the subquery, set [Product].[Category].MEMBERs on outer 1 axis return two members [Product].[Category].[ALL] and [Product].[Category].[Bikes], and set the default member of attribute [Product].[Category] on axis 1 to [Bike], then the calculated member [ount product of bikes] will return the expected value with the CurrentMember.