Search code examples
ssasmdx

TopCount filtered on a date dimension value


I'm attempting to get the top 10 countries by value from any measures where the discount rate is -20, and for a specific date. I've created a simple dynamic set defined as:

CREATE DYNAMIC SET CURRENTCUBE.[Top10CountryBy20Disc]
 AS 

TopCount
        ( [Customer].[Country].members, 
                10,   [Discount].[Discount].&[-20%])
      ;

This gives me the top 10 customers summed by the overall measure value, but I need to filter to a specific date. The overall top 10 won't be the same as the top 10 on a particular date, so I need to include some date context. Currently the numbers I get back for each country are correct, but it is the list of countries (the top 10 list) that is incorrect.

I use the set [Latest] listed below in a lot of other reports, and this works just fine, but am struggling to combine this when using the above set.

CREATE DYNAMIC SET CURRENTCUBE.[Latest]
 AS FILTER( 
            [Date].[Date Key].[Date Key].members, IsDate([Date].[Date Key].currentmember.membervalue) 
AND (

            DateDiff("d", [Date].[Date Key].currentmember.membervalue,  IIF(Weekday(Now()) = 2, 3, 1)
            
    );

Logically I am trying to do something along the lines of the below, which is invalid syntax:

TopCount
        ( [Customer].[Country].members, 
                10,   ([Discount].[Discount].&[-20%], [Latest]))
      ;

Would be grateful for some suggestions/direction on this.


Solution

  • This approach solved my issue:

    GENERATE ( [Latest],
                 {TopCount
                    ( descendants([Customer].[Country],,AFTER), 
                        10,   
                        VBA!Abs(([Discount].[Discount].&[-20%], ([Measures].[MeasureName],[Date].[Date Key].currentmember)))
                    )
                }
             );