SQL Server Developer Center > SQL Server Forums > SQL Server Analysis Services > Find last non empty child in CASE statement?
Ask a questionAsk a question
 

AnswerFind last non empty child in CASE statement?

  • Wednesday, November 04, 2009 2:09 PMr9mcgon Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I am aggregating a measure using LastChild.

    So, when it comes to serving a YTD total for an incomplete year, I get NULL.

    What I want to return is the last non empty child of the member requested. The hierarchy in question has 3 levels, year, quarter and month.

    The query I am using is below.

    Does anyone have any suggestions?

    WITH

     

    MEMBER [Measures].[VLDE] AS

     

    CASE [Measures].[FactValue]

     

     

    WHEN NULL THEN

     

    -- Get the hierarchy level requested (1 = year, 2 = QTR)

     

    CASE [Time].[Hierarchy].CurrentMember.Level.Ordinal

    -- I want to get the last NON EMPTY child here, not just the last child (which could be empty)

     

    WHEN 1 THEN ([Time].[Hierarchy].CurrentMember.LastChild, [Measures].[FactValue])

     

     

    END

     

    ELSE [Measures].[FactValue]

     

     

    END

    SELECT

     

     

    {[Measures].[VLDE]}

     

     

    ON AXIS(0)

    ,{[dCountry].[CountryName].

     

    Members}

     

     

    ON AXIS(1)

    FROM

     

    [LocalCube]

    WHERE

     

    ([Time].[Hierarchy].[Year].&[2010])

Answers

  • Wednesday, November 04, 2009 7:53 PMDeepak PuriMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    ".. What I want to return is the last non empty child of the member requested .." - so would another "LastNonEmpty" measure on the same field serve your purpose more simply?
    - Deepak
    • Marked As Answer byr9mcgon Thursday, November 05, 2009 1:37 PM
    •  

All Replies

  • Wednesday, November 04, 2009 7:53 PMDeepak PuriMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    ".. What I want to return is the last non empty child of the member requested .." - so would another "LastNonEmpty" measure on the same field serve your purpose more simply?
    - Deepak
    • Marked As Answer byr9mcgon Thursday, November 05, 2009 1:37 PM
    •  
  • Thursday, November 05, 2009 1:38 PMr9mcgon Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Yes, much more simply. I wouldn't have thought of that. Thanks DeePak.