Blog Post

MDX+SSRS #34 – Query not returning results: there are good reasons

,

When we are learning MDX, we unavoidably have to deal with the tools we use. Adding confusions about the behaviors of the different tools to our still fragile understanding of the MDX language itself can create huge frustration for learners.

Here is one of them. In developing SSRS reports, we frequently need to create report parameters using members from dimensions as choices for users to pick (they are referred to as pick lists).

Empty Measure (COLUMNS) + NON EMPTY keyword (ROWS) = no results

If you already know how to use the Query Designer in SSRS in graphical mode to create basic MDX queries, you might want to venture further to see if you can create a pick list by yourself. Let’s use Adventure Works cube as our example, and assume that you want to create a product pick list by retrieving all the members from the Product dimension. Very soon, you will realize that your dataset in SSRS will not return any product at all.

Here is what you might have done. In the Query Designer in SSRS, you just simply find the Product dimension and also the Product attribute hierarchy, and drag it to the report area. There is no product returned.

image

As a matter of fact of fact, there would be no data returned at all no matter which dimension you choose.

Now let’s click on the toggle button on the upper right corner and switch to the query editing mode.

image

We see a couple of things in this query.

  • There is an empty set on the COLUMNS axis: { } ON COLUMNS
  • There is NON EMPTY keyword on both the COLUMNS axis and the ROWS axis.

The combination of the above two creates an empty result set. Let’s remove the NON EMPTY keyword on the ROWS axis, and click on the red execution icon on the top. A list of products came up.

image

At this point, you night wonder why SSRS even bothered to use the NON EMPTY keyword by default if it is causing the query not returning any results.

There is a good reason why it does it. Cube space can be very large, and typically it is very sparse. When writing MDX, we spend a lot of effort trying to remove the empty cells from our results to improve both the query time and the data rendering time. SSRS is no exception. By adding NON EMPTY keyword, it assumes that we do not want to include any products that do not have any fact data. Unfortunately in this case, you didn’t get a chance to specify what the fact data (measure) is; SSRS added an empty set on the first axis by default. We get a combination of Empty Measure (COLUMNS) + NON EMPTY keyword (ROWS) which produces no results .

[ALLMEMBERS] = no result

I have seen another good reason why a query would not return the pick list.

you can try to run the following query. It would not return any results.

SELECT  {} on 0,
        [Product].[Product].[ALLMEMBERS] ON 1
FROM    [Adventure Works]

Now remove the brackets around ALLMEMBERS, you will see the result set.

SELECT  {} on 0,
        [Product].[Product].[ALLMEMBERS] ON 1
FROM    [Adventure Works]

In SSMS, by removing the brackets around ALLMEMBERS, ALLMEMBERS’s color turned from black to maroon. 

image

You might have already guessed the reason.

  • ALLMEMBERS is a MDX built-in function: [Product].[Product].ALLMEMBERS will evaluate the product hierarchy in the product dimension and returns a set that contains all members of the product hierarchy, which includes the top level member [All Products], all products, and all calculated members if any. See http://technet.microsoft.com/en-us/library/ms144768.aspx for details on the ALLMEMBERS function.
  • [ALLMEMBERS] is a member with the name of ALLMEMBERS. [Product].[Product].[ALLMEMBERS] represents a member with name ALLMEMBERS that does not exist in the product hierarchy.

More Information on the NonEmpty() function and the Non Empty keyword

In MDX, both the NonEmpty() function and the Non Empty keyword can be used to remove empty rows and columns. The difference between the NonEmpty() function and the Non Empty keyword is well explained in the recipe “Knowing the difference between NONEMPTY() function and the NON EMPTY keyword” in Chapter 1 of the book “MDX with SSAS 2012 Cookbook”.

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating