简体   繁体   中英

Calculate maximum value for a measure column without using dimension in mdx query

I would like to calculate maximum value for a measure column without using dimension in mdx query. I tried the following query to achieve this.

WITH MEMBER [Measures].[Max key] AS
    Max([Internet Sales Amount].Members,[Internet Sales Amount].currentmember.MEMBER_KEY)
SELECT {[Measures].[Max key]} on COLUMNS
FROM [Adventure Works]

But I got the error in result.

Can anyone suggest me how to achieve my requirement using mdx query?

You've written this:

WITH 
  MEMBER [Measures].[Max key] AS 
    Max
    (
      [Internet Sales Amount].MEMBERS
     ,[Internet Sales Amount].CurrentMember.Member_Key
    ) 
SELECT 
  {[Measures].[Max key]} ON COLUMNS
FROM [Adventure Works];

[Internet Sales Amount] is a measure and therefore a numeric expression so you cannot apply the functions MEMBERS or CurrentMember . [Internet Sales Amount] will not even have keys - so why are you trying to find a max key?

Max is defined here: https://docs.microsoft.com/en-us/sql/mdx/max-mdx

You have no choice but to include a set for the max to work over:

Max( Set_Expression [ , Numeric_Expression ] )

This is a valid use of max:

WITH 
  MEMBER [Measures].[Max Sales] AS 
    Max
    (
      [Product].[Category].[Category]
     ,[Internet Sales Amount]
    ) 
SELECT 
  [Product].[Category].[Category] ON ROWS
 ,{
    [Internet Sales Amount]
   ,[Measures].[Max Sales]
  } ON COLUMNS
FROM [Adventure Works];

It returns this:

在此处输入图片说明

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