简体   繁体   中英

SSRS : How to use average function of mdx query using parameters

Here My MDX Query :

SELECT 
  NON EMPTY 
    {[Measures].[Price]} ON COLUMNS
 ,NON EMPTY 
    {
        [Dim Date].[Date Key].[Date Key].ALLMEMBERS*
        [Dim Date].[Year].[Year].ALLMEMBERS*
        [Dim Instrument].[Instrument Code].[Instrument Code].ALLMEMBERS*
        [Dim TP Folio].[P Folio Code].[P Folio Code].ALLMEMBERS*
        [Dim Market Price].[Date].[Date].ALLMEMBERS
    }
  DIMENSION PROPERTIES 
    MEMBER_CAPTION
   ,MEMBER_VALUE
   ,MEMBER_UNIQUE_NAME
   ON ROWS
FROM 
(
  SELECT 
    StrToSet
    (@DimTPFolioPFolioCode
     ,CONSTRAINED
    ) ON COLUMNS
  FROM 
  (
    SELECT 
      StrToSet
      (@DimInstrumentInstrumentCode
       ,CONSTRAINED
      ) ON COLUMNS
    FROM 
    (
      SELECT 
        StrToSet
        (@DimDateYear
         ,CONSTRAINED
        ) ON COLUMNS
      FROM [DSV_SIAPDW]
    )
  )
)
CELL PROPERTIES 
  VALUE
 ,BACK_COLOR
 ,FORE_COLOR
 ,FORMATTED_VALUE
 ,FORMAT_STRING
 ,FONT_NAME
 ,FONT_SIZE
 ,FONT_FLAGS;

I have 3 parameters @DimDateYear, @DimInstrumentInstrumentCode and @DimTPFolioPFolioCode, and then i want to show the average from [Measures].[Price] per Years, but i don't know how to get the AVERAGE value From [Measures].[Price] with 3 parameters. anybody can help me ? I'm New in Mdx Query.

Here is an example that you can play with in AdvWrks :

WITH 
  MEMBER [Measures].avgOverAllYears AS 
    Avg
    (
      [Date].[Calendar].[Calendar Year].MEMBERS
     ,[Measures].[Amount]
    ) 
SELECT 
  {
    [Measures].[Amount]
   ,[Measures].avgOverAllYears
  } ON 0
 ,[Date].[Calendar].[Calendar Year] ON 1
FROM [Adventure Works];

The result of the above is this:

在此处输入图片说明

You can see that the additional column that I created using the WITH clause gives us the average over all the years.

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