English 中文(简体)
MDX WHERE NOT IN() equivalent in many-to-many dimension
原标题:
  • 时间:2009-12-16 15:22:22
  •  标签:
  • ssas
  • mdx

I have a many-to-many dimension in my cube (next to other regular dimensions). When I want to exclude fact rows in my row count measure, I usually do something like the following in MDX

SELECT [Measures].[Row Count] on 0
FROM cube
WHERE ([dimension].[attribute].Children - [dimension].[attribute].&[value])

This might seem more complicated than needed in this simple example, but in this case the WHERE can grow sometimes, also including UNIONs.

So this works for regular dimensions, but now I have a many-to-many dimension. If I perform the trick above it does not produce the desired result, namely I want to exclude all rows that have that specific attribute in the many-to-many dimension.

Actually it does exactly what the MDX asks, namely count all rows, but ignore the specified attribute. Since a row in the fact table can have multiple attributes in a many-to-many dimension, the row will still be counted.

That s not what I need, I need it to explicitly exclude rows that have that dimension attribute value. Also, I might exclude multiple values. So what I need is something similar to T-SQL s WHERE .. NOT IN (...)

I realize that I can just subtract the resulting values from [attribute].all and [attribute].&[value], but that won t work any more when UNIONing multiple WHERE statements.

Anybody got a good idea on how to solve this?

Thanks in advance,

Delta

问题回答

I have not tested this, but I think you could do this if you had an attribute that was at the same level of granularity as the rows (so probably implemented as a fact relationship).

So if you wanted to count the number of orders that did NOT have a product category of bikes (assuming a M2M relationship between OrderID and Category) then something like the following should work. (you can find more info on the EXISTS function in Books Online)

[Orders].[Order ID].[Order ID].Members 
- EXISTS([Orders].[Order ID].[Order ID].Members
       , [Product].[Category].&[Bikes]
       , "Order Facts")

Although it could be quite slow as this sort of query is forcing the SSAS engine to add up a lot of facts from a low level.

Have you tried the EXCEPT command? It s syntax is like the following:

EXCEPT({the set i want}, {a set of members i dont want})

You could use the Filter function:

SELECT [Measures].[Row Count] on 0
FROM [cube]
WHERE Filter([dimension].[attribute].Children, [dimension].CurrentMember.MemberValue <> value)




相关问题
In SSAS, can parent-child DATAMEMBER name be customised

In a parent-child dimension in SSAS, the datamember is automatically named the same as the parent. E.g. Division X Risk Register Division X Risk Register Department A Risk Register Department B ...

Adding a Total column to MDX

I have the following query that gives me an extract (I am putting this into a CSV from my cube). I want to show the Total of all NRx in a column as the first column NRx and the rest of the NRx ...

using colors in calculated member

Im using this query in MDX for a calculate measure topcount(nonempty([StatusPlanes].[Status].Status.members,[Measures].[Planes]),1)(0).member_caption this will bring me this result Dimension1 ...

Using colors with MDX calculated measure

I m using this query in MDX for a calculated measure topcount(nonempty([StatusPlanes].[Status].Status.members,[Measures].[Planes]),1)(0).member_caption This will bring me this result Dimension1 ...

Calculated Member for Cumulative Sum

First some background: I have the typical Date dimension (similar to the one in the Adventure Works cube) and an Account dimension. In my fact table I have daily transaction amounts for the accounts. ...

What is MDX and what is its use in SAP BPC

I would like to know more about "MDX" (Multidimensional Expressions). What is it? What is it used for? Why would you use it? Is it better than SQL? What is its use in SAP BPS (I haven t seen BPC, ...

热门标签