0

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

Arian
  • 12,793
  • 66
  • 176
  • 300

1 Answers1

2

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])}
MoazRub
  • 2,881
  • 2
  • 10
  • 20
  • Thanks, Can you explain why you use `[Product].[Category].defaultmember` and `[Customer].[Customer Geography].[Country].[Country], [Product].[Category].&[Bike])`? I don't understand the logic of your answer – Arian Nov 05 '19 at 10:39
  • 1
    @Arian i have edited the answer to add explanation. Incase you are still confused contact me on skype (id: moazrub) – MoazRub Nov 05 '19 at 14:28