Search code examples
sql-server-2008ssasmdx

Improving the performance of a COUNT operation in MDX


I have a fairly complex OLAP database, which basically amounts to a "header" record, and a huge number of "Members" which belong to that header.

My current MDX query gets the aggregated sum "Value" of members sliced by Age band and type of member. Here is the query:

SELECT 
(
    [Measures].[Member Value]
) 
ON COLUMNS, 
NON EMPTY  
( 
    {
       [Header].[Client Hierarchy].[Group Name].&[The Company]&[UK]&[ABC Group],
       [Header].[Client Hierarchy].[Group Name].&[The Company]&[UK]&[DEF Group]
    }
    [Header].[Member Type].[Member Type],
    [Member].[Age Band].[Age Band]
) 
ON ROWS 
FROM [Cube]
WHERE 
(
  [Header].[Another Attribute].&[Something],    
  [Header].[Created Date].&[2010-12-31T00:00:00],
  [Member].[A Boolean Attribute].&[False]
)

I am trying to add another measure to this query to get the number of members aggregated in each row of the resultset. I achieved this using this calculated member:

WITH MEMBER [Measures].[Member Count] AS
COUNT(  
    EXISTING ([Member].[Id].[Id],[Measures].[Member Value])
    ,EXCLUDEEMPTY
)

And of course added it into the COLUMNS

SELECT 
(
    [Measures].[Member Value],
    [Measures].[Member Count]
) 
...

However this chnages the query from taking ~1second originally to ~1:14minutes

Im thinking this is more to do with my cube structure than the query itself, does anyone have any hints as to what I need to change in my cube structure, or possibly a more efficient way of querying the same thing? I have seen some examples online of using SUM rather than count but they were more to do with COUNT and FILTER together.


Solution

  • For the record I determined that I already had a Measure that would sum up my records.

    The member table had a measure which represented "The number of members this record represents" This had a 1 in it for all the records I was looking at (single members). Simply adding this measure summed that value across my slice.