Tuesday, July 17, 2012

Filtering Dimension Members having the same name in a MDX Query...

Sometimes different dimension members having different key values may have the same name. This kind of situations mainly occurs when we set a default value to those unknown dimension member values. As an example if we set the value as "Unknown" for the items in the sales records, which do not match our existing items, then the key value for those items in the cube will be different but the name value will be same.

But if we try to filter those "Unknown" member values using the query designer, it will only filter the selected members. Otherwise we have to select all the members having the name value as Unknown, to filter those. But if there are large number of members having the same name, then it will be difficult and not feasible to select all those.

We can filter those in the MDX query using INSTR function. The query will looks as below.

   1: SELECT NON EMPTY { [Measures].[Sales] } ON COLUMNS, NON EMPTY { (
   2: [Items—Items_Vendor_Item].[Item Name].ALLMEMBERS ) } ON ROWS FROM
   3: [SalesCube]
   4: WHERE FILTER([Items—Items_Category_Item].[Item].Members, INSTR([Items—Items_Category_Item].CurrentMember.Name,'Unknown')=0)

Since it is not allowed to use the same hierarchy more than once in the query, two dimension hierarchies are used which contains Items.

No comments:

Post a Comment