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

StackOverflow https://stackoverflow.com/questions/23566741

  •  19-07-2023
  •  | 
  •  

Frage

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

War es hilfreich?

Lösung

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.

Andere Tipps

USE CROSS JOIN creates all the combinations of the 'Direct" member and the dates in my range as tuples for my WHERE slicer. I think this is the right answer.

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

Your slicer predicate tries to do a crossproduct of a set and a member. That's not possible.

Add brackets ( '{' & '}' ) around the date member to turn it into a set of one member. It'll become a compound predicate which includes your two sets.

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]}
)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top