简体   繁体   中英

How to filter time hierarchy based on anothr attribute's value in MDX

I want to create a calculated member. I have a time dimension hierarchy" YQM", which has Year/Quarter/Month. The calculated member should find YTD till the current month. However, the value of current month will come from database. I have created a attribute, "CP" which returns the current month value. Please tell me how to create the calculated member. Please note "CP" is not in the same hierarchy YQM.

I don't understand why you are using Aggregate . So, I will assume that it is there for some purpose, which you have't clarified. Now, if the members of [YQM].[Month] and [Dim].[CP] are of the same format, then you can try the code below:

   Aggregate(
        PeriodsToDate([Dim].[YQM].[Month].MEMBERS,
            FILTER([Dim].[YQM].[Month].MEMBERS, 
            [YQM].[Month].CURRENTMEMBER.member_value = [Dim].[CP].FirstChild.member_value)
        )
    )

Why not try playing with the function YTD . The following should give you the monthly amount in the first column of data and then the YTD amount in the next column:

WITH MEMBER [Measures].[YearToDate] AS
  AGGREGATE(
    YTD()
   ,[Measures].[someMeasureInCube]
  )
SELECT 
  {
    [Measures].[someMeasureInCube], 
    [Measures].[YearToDate]
  } ON 0,
  [Dim].[YQM].[Month].MEMBERS ON 1
FROM [yourCube]

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