Search code examples
ssasmdxolapcube

Show non empty levels in MDX


How I can list levels for one dimension, which have non empty associated measure?

Let assume that I have measure Budget. We created budget four times in a year, so this measure contains all of these values. I need to check only one prediction (category) in the report.

This query returns me all levels:

WITH
MEMBER [Measures].[Label] AS [Dim_Budget Category].[Category].CURRENTMEMBER.MEMBER_CAPTION 
MEMBER [Measures].[Value] AS [Dim_Budget Category].[Category].CURRENTMEMBER.UNIQUENAME 

SELECT 
{
    [Measures].[Label], 
    [Measures].[Value]
} ON 0,
{
    [Dim_Budget Category].[Category].&[BUDGET],
    [Dim_Budget Category].[Category].&[YEP_1],
    [Dim_Budget Category].[Category].&[YEP_2],
    [Dim_Budget Category].[Category].&[YEP_3]
} ON 1
FROM [Retail] 

Now I am trying to add logic which check If category have any value in measure Budget. If yes, the query should return this level.


Solution

  • To test if [Dim_Budget Category].[Category].&[YEP_1] is empty against a measure [Measures].[Budget] just wrap NonEmpty around it:

    NonEmpty(
      [Dim_Budget Category].[Category].&[YEP_1]
     ,[Measures].[Budget]
    )