Please consider this MDX
query:
SELECT {[Measures].[Internet Sales Amount]} ON COLUMNS,
[Date].[Calendar Year].MEMBERS ON ROWS
FROM [Adventure Works]
How Can I add WHERE
clause to above query with these three criteria:
1) Where [Customer].[Customer Geography].[Country].&[United States] AND [Product].[Category].&[Bike]
2) Where [Customer].[Customer Geography].[Country].&[United States] OR [Product].[Category].&[Bike]
3) Where ([Customer].[Customer Geography].[Country].&[United States] OR [Product].[Category].&[Bike]) AND [Date].[Year].&[2008]
Thanks
1) Where [Customer].[Customer Geography].[Country].&[United States] AND [Product].[Category].&[Bike]
For this your where clause will be
Where ([Customer].[Customer Geography].[Country].&[United States], [Product].[Category].&[Bike])
The above code defines a tuple which consits of data on from United States Bikes Sales
2) Where [Customer].[Customer Geography].[Country].&[United States] OR [Product].[Category].&[Bike]
For this your Where clause will be
Where
{([Customer].[Customer Geography].[Country].&[United States], [Product].[Category].defaultmember),
([Customer].[Customer Geography].[Country].[Country], [Product].[Category].&[Bike])}
In this case you want data when either the country is USA or the Product is bike. So I have defined two tuples the first one says that country is USA and the product category can be any product category. In the next tuple I say that the country can be any country but the product is Bike. In MDX each Tuple with in a set should be equal in terms of hierarchy and in terms of the position of hierarchy. In the above case i cannot make a set saying
{
([Customer].[Customer Geography].[Country].&[United States]),
([Product].[Category].&[Bike])
}
This Set is not possible in MDX, therefore in the first tuple I mentioned "[Product].[Category].defaultmember" which means no particular value is defined, similarly in the next tuple i used "[Customer].[Customer Geography].[Country].[Country]" since this is user hierarchy I cannot use default member, so I used this expression.
3) Where ([Customer].[Customer Geography].[Country].&[United States] OR [Product].[Category].&[Bike]) AND [Date].[Year].&[2008]
For this you need to modify the where clause and the on rows. So for this part your query will be
SELECT {[Measures].[Internet Sales Amount]} ON COLUMNS,
[Date].[Calendar Year].&[2011] ON ROWS -- in my sample the strong name of 2011 is &[2011] yours may be diffrent
FROM [Adventure Works]
Where
{([Customer].[Customer Geography].[Country].&[United States], [Product].[Category].defaultmember),
([Customer].[Customer Geography].[Country].[Country], [Product].[Category].&[Bike])}