Search code examples
sql-server-2012ssasmdx

Return all levels below a specific member


In the following I was hoping to return all of the tree below the member Engineering.
I'm guessing I'm misusing IS?
Should I be using membervalue?
I thought using the specific member would be more efficient?

WITH 
    MEMBER [Measures].[LevelName] AS
        [Employee].[Employee Department].Level.Name
    MEMBER [Measures].[LevelNumber] AS
        [Employee].[Employee Department].Level.Ordinal
SELECT
    {
    FILTER(
        [Employee].[Employee Department].AllMembers,
        [Employee].[Employee Department].[Department] IS 
            [Employee].[Employee Department].[Department].&[Engineering]
        )
    } ON 1,
    {
    [Measures].[LevelName],
    [Measures].[LevelNumber] 
    } ON 0
FROM [Adventure Works] 

Here is the error message:

Executing the query ... Query (10, 3) The Is function expects a level expression for the 2 argument. A member expression was used. Execution complete


Solution

  • You don't need to use the FILTER function to obtain all child members belonging to a specific member. Just do something like this instead:

    SELECT
    {
        [Employee].[Employee Department].[Department].&[Engineering].CHILDREN
    } ON 1,
    ...
    

    If you want the entire tree below a specific member, use the DESCENDANTS function:

    SELECT
    {
        DESCENDANTS([Employee].[Employee Department].[Department].&[Engineering],
            [Employee].[Employee Department].[Department], AFTER)
    } ON 1,
    ...