Search code examples
mdxpentahoolapmondrian

MDX query with dimension attribute between two values and another dimension attribute equal to another value


I'm trying to build a query that selects the Top 10 products (with most likes) made by users with age between 1 and 20 years old, at the year 2014. I'm trying to use the following query:

WITH SET [TopProducts] AS TOPCOUNT([Products].[Name].Members,10,[Measures].[Likes])
SELECT {[Measures].[Likes]}
ON COLUMNS, {[TopProducts]}
ON ROWS FROM [Likes]
WHERE (
  {[Ages].[Age].[1]:[Ages].[Age].[24]},
  [Date].[Year].[2014]
)

This query returns an error: No function matches signature '(<Set>, <Member>)'

If I remove the [Date.Date].[Year].[2014] from the query, it works smoothly, so I think the problem is in the formulation of the where clause. What am I doing wrong here? Is this the way to do this query?

Thanks


Solution

  • On the WHERE clause you need to specify a Tuple. A Tuple is an unordered set of members from 1 or more dimensions.

    Try this:

    WITH 
      SET [TopProducts] AS TOPCOUNT([Products].[Name].Members,10,[Measures].[Likes])
      MEMBER [Ages].[Range] as Aggregate( [Ages].[Age].[1]:[Ages].[Age].[24] )
    SELECT {[Measures].[Likes]}
      ON COLUMNS, {[TopProducts]}
      ON ROWS FROM [Likes]
    WHERE ( [Ages].[Range], [Date].[Year].[2014] )
    

    The Aggregate function takes a set and returns a member which is the aggregation of all elements of the set. Now your tuple on the WHERE clause is correct, as it references two members of two different dimensions.