简体   繁体   中英

MDX calculated member dimension context

I have the following calculated member which represents the quantity of "overstocked" products:

WITH 
    MEMBER [Measures].[Overstocked Items Count] AS 
        FILTER(
            [Items].[Item No].CHILDREN,
            [Measures].[Overstocked Qty] > 0
        ).COUNT

It works just fine for any linked to the measure group dimension except for the Items dimension itself and the reasons are obvious. Is there a way to create a calculated member that would respect the context it is evaluated in? So basically if this member is evaluated against an item group code I need items count by those groups, not the entire items set.

EXISTING is a useful keyword that can add the current context to your measure:

WITH 
    MEMBER [Measures].[Overstocked Items Count] AS 
        FILTER(
            EXISTING([Items].[Item No].CHILDREN),
            [Measures].[Overstocked Qty] > 0
        ).COUNT

EXISTING is very good when you want to know the members present from a different hierarchy within the same dimension . eg say you have USA selected from the country hierarchy (in geography dimension) and you need to count state/county members from a stateCounty hierarchy that is also part of the geography dimension then EXISTING is the correct choice.

If you want to go across dimensions so say you have USA selected and you'd like to count customer, from the customer dimension who are associated with the USA then I don't think EXISTING will work - you'll need to explore either EXISTS or NONEMPTY .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM