Search code examples
ssasmdxdimensions

MDX Get MAX MEMBER_KEY from Dimension


I have a very simple SSAS dimension which looks like this:

Dimension Name: DimKeyword

1 Attribute: Keyword with KeywordID as the KeyColumn and Keyword (name) as the NameColumn

Using MDX, I want to get one row with the Max MEMBER_KEY for the DimKeyword dimension (without listing all the Keywords), so far I have:

WITH MEMBER KeywordID as
[Dim Keyword].[Keyword].currentmember.MEMBER_KEY
SELECT {KeywordID} on COLUMNS
FROM [Some Cube]

Although this seems to only return 0 (which I assume is for the member ). Can anyone help?

Thanks!


Solution

  • You can use the max function:

    WITH MEMBER [Measures].[Max key] AS
        Max([Dim Keyword].[Keyword].Members, [Dim Keyword].[Keyword].currentmember.MEMBER_KEY)
    SELECT {[Measures].[Max key]} on COLUMNS
    FROM [Some Cube]
    

    And if you want to have the Keyword member that has the highest MEMBER_KEY, you can use:

    TopCount([Dim Keyword].[Keyword].Members, 1, [Dim Keyword].[Keyword].currentmember.MEMBER_KEY).Item(0).Item(0)