问题
Old SQL developer, new to MDX: Need help with a requirement to include small totals in a running total but not show the contributing rows of those small totals.
Consider this data
Amount Running Total
Denver 6,321 6,321
Portland 8,426 14,747
Boise 19,222 33,969
Helena 23,257 57,226
Bozeman 31,225 88,451
Seattle 36,894 125,345
My requirement is to not show any amounts under 15,000 but instead show the running total that includes them. I must not show amounts or running totals less than 15,000. This is to insure that small numbers can't be identified to specific cities.
like this:
Amount Running Total
Other 19,222 33,969
Helena 23,257 57,226
Bozeman 31,225 88,451
Seattle 36,894 125,345
Or, ideally, what is needed:
Amount
Other 33,969
Helena 23,257
Bozeman 31,225
Seattle 36,894
Thanks for any assistance MartinA
回答1:
After a few whiteboard sessions, my co-conspirator came up with a simple solution: Add a new measure, calculating the difference between the running total and the city amount. When this difference is less than the threshold, then this will be the rolled up row that is to contain the City name of “Other” and also use the running total rather than city total. Kudos to Tyson
Here's some example code:
WITH
SET [OrderedSet] AS
Nonempty
(
ORDER
([Age].[Age Group B].[Age Group B].Members,
[Measures].[Emergency Room Visits per 1,000 Member Months],
BASC
)
)
MEMBER [Measures].[RowNumber] AS
Rank([Age].[Age Group B].CURRENTMEMBER,
[OrderedSet]
)
MEMBER [Measures].[Running Total] as
Sum(
Head
([OrderedSet],
([Measures].[RowNumber],[Age].[Age Group B].CurrentMember)
),
[Measures].[Emergency Room Visits per 1,000 Member Months]
)
MEMBER [Measures].[Ttl_RunTtl_Diff] AS
[Measures].[Running Total] - [Measures].[Emergency Room Visits per 1,000 Member Months]
MEMBER MEASURES.NewAge AS
IIF([Measures].[Ttl_RunTtl_Diff] = 0 OR [Measures].[Ttl_RunTtl_Diff]>15000
, [Age].[Age Group B].CURRENTMEMBER.Name, "Other")
MEMBER MEASURES.NewTotal AS
IIF([Measures].[Ttl_RunTtl_Diff] = 0 OR [Measures].[Ttl_RunTtl_Diff]>15000
, [Measures].[Emergency Room Visits per 1,000 Member Months], [Measures].[Running Total])
SELECT NON EMPTY
{
[Measures].[Emergency Room Visits per 1,000 Member Months],
[Measures].[Member Months],
[Measures].[Emergency Room Visits],
[Measures].[Running Total],
[Measures].[Ttl_RunTtl_Diff],
[Measures].[NewAge],
[Measures].[NewTotal]
}
ON COLUMNS,
NON EMPTY
FILTER({[OrderedSet]}
, [Measures].[Running Total] > 15000 )
ON ROWS FROM [Model]
来源:https://stackoverflow.com/questions/48527568/ssas-mdx-calculate-running-total-but-exclude-less-significant-rows