In this post I will demonstrate the difference between “non empty” and “nonempty” in MDX. Not everyone knows the difference between these functions.
Lets write a simple MDX
SELECT { [Measures].[Reseller Sales Amount], [Measures].[Discount Amount] } ON COLUMNS, [Geography].[City].[City] ON ROWS FROM [Adventure Works]
And the result will look like this
As you can see there are cities with no sales and no discount. If I add the “NONEMPTY” function I will remove all rows where both measures are NULL.
SELECT { [Measures].[Reseller Sales Amount], [Measures].[Discount Amount] } ON COLUMNS, NON EMPTY [Geography].[City].[City] ON ROWS FROM [Adventure Works]
But to remove all rows with NULL in discount amount I must use the “nonempty”. To make this work I will have to create a new measure that prints NULL if the value are 0 🙂
WITH MEMBER [Measures].[Discount Amount2] AS IIF([Measures].[Discount Amount] = 0, NULL, [Measures].[Discount Amount]) SELECT { [Measures].[Reseller Sales Amount], [Measures].[Discount Amount2] } ON COLUMNS, NONEMPTY ([Geography].[City].[City], [Measures].[Discount Amount2]) ON ROWS FROM [Adventure Works]
The “NONEMPTY” and “NON EMPTY” can be replaced by a filter. Like this
WITH MEMBER [Measures].[Discount Amount2] AS IIF([Measures].[Discount Amount] = 0, NULL, [Measures].[Discount Amount]) SELECT { [Measures].[Reseller Sales Amount], [Measures].[Discount Amount2] } ON COLUMNS, FILTER ([Geography].[City].[City], NOT IsEmpty([Measures].[Discount Amount2])) ON ROWS FROM [Adventure Works]