Search code examples
mdxperformancepoint

MDX - TopCount plus 'Other' or 'The Rest'


I have created an MDX query which calculates the TOP 10 ZipCodes (according to my Patient Stay measure) as such:

WITH
MEMBER [Discharge Date].[Y-M-D].[ Aggregation] AS 'AGGREGATE( EXISTING { [Current Month] } )', SOLVE_ORDER = 0

SELECT
NON EMPTY { [Measures].[Patient Stays] }
ON COLUMNS,

TOPCOUNT({ ORDER( HIERARCHIZE( { [Patient].[ByZipcode].[All].CHILDREN } ), ( [Measures].[Patient Stays] ), BDESC ) }, 10)
ON ROWS

FROM [Patient Stay]

WHERE ( [Discharge Date].[Y-M-D].[ Aggregation], [Facility].[ByAffiliation].CURRENTMEMBER, [Facility].[ByRegion].CURRENTMEMBER )

This query is used to populate a PerformancePoint 100% Stacked Bar chart. The client has asked that since this is a !00% based chart, we lump the rest of the zip codes into an "Other" field, such that there should be 11 values: one for each of the top 10, and an eleventh which is a sum of the remaining Zip Codes.

I am an extreme novice to MDX, but this doesn't souund like it should be impossible. Does anyone have any ideas or suggestions?


Solution

  • I'll do my best with untested code, so here goes:

    WITH
    MEMBER [Discharge Date].[Y-M-D].[ Aggregation] AS 'AGGREGATE( EXISTING { [Current Month] } )', SOLVE_ORDER = 0
    
    SET [Top10ZipCodes] AS 
        (TOPCOUNT({ ORDER( HIERARCHIZE( { [Patient].[ByZipcode].[All].CHILDREN } ), ( [Measures].[Patient Stays] ), BDESC ) }, 10))
    
    MEMBER [Patient].[ByZipCode].[OtherZipCodes] AS 
        (AGGREGATE({EXCEPT([Patient].[ByZipCode].Members, [Patient].[ByZipCode].[Top10ZipCodes])}))
    
    SELECT
    NON EMPTY { [Measures].[Patient Stays] }
    ON COLUMNS,
    
    {[Top10ZipCodes], [Patient].[ByZipCode].[OtherZipCodes]}
    ON ROWS
    
    FROM [Patient Stay]
    
    WHERE ( [Discharge Date].[Y-M-D].[ Aggregation], [Facility].[ByAffiliation].CURRENTMEMBER, [Facility].[ByRegion].CURRENTMEMBER )
    

    What this does is creates a set of your top 10 ZIP codes, and then aggregates (different than sum!!!) all the ZIP codes, with the exception of your top 10.

    Also, if this is a common set (top 10 ZIP codes), you may want to make a set on the cube, where you can reuse it ad nauseum, without having to change every MDX query you have.

    Cheers,
    Eric