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

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 18:07:02

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/787532/mdx-topcount-plus-other-or-the-rest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!