Showing posts with label multiselect. Show all posts
Showing posts with label multiselect. Show all posts

Monday, March 12, 2012

MDX Select - To use in Client App

We have a client app that used MDX to display data in the fromtend in grid. And we have requirement to filter by a dimension value (multiselect) + also display the same in the grid. But I'm aware that this is not possible using basic MDX.

I'm trying to acheive something similar to below query i.e. A dimension in slicer Axis and also in rows. Is it possible?

SELECT { [Measures].[LTD Value]} ONCOLUMNS,

NONEMPTY

(

[Currency].[Currency].[Currency].Members ,

[Trade].[Source Trade Code].[Source Trade Code].Members

) ONROWS

FROM [MyCube]

WHERE (

[Calendar].[Calendar].[Date].&[2007-01-04T00:00:00]

,{[Currency].[Currency].[Currency].[EUR], [Currency].[Currency].[Currency].[GBP] }

);

thanks,

Arun

You can define an explicit set on an axis and do a cross product of that set against another:

Code Snippet

select

[Measures].[Reseller Sales Amount] onColumns,

{[Date].[Calendar].[Month].[May 2004],

[Date].[Calendar].[Month].[June 2004]} * [Product].[Category].[Category].MembersonRows

from [Adventure Works]

If you need to make the set more dynamic, look at the STRTOMEMBER() and STRTOSET() functions.

Thanks,

Bryan

|||

Hi Arun,

Have you tried using a sub-select MDX query, like:

select

{[Measures].[Average Rate]} on 0,

[Destination Currency].[Destination Currency Code].[Destination Currency Code] on 1

from (select

{[Destination Currency].[Destination Currency Code].[EUR],

[Destination Currency].[Destination Currency Code].[GBP]} on 0

from [Adventure Works])

where [Date].[Calendar].[Date].[January 4, 2004]

--

Average Rate
EUR .92
GBP 1.46

|||Thanks guys. Both the above solution works.

Monday, February 20, 2012

MDX Multiselect and existing keyword usage

WITH

MEMBER LastYearSales
as
'
sum(
existing [Time].[Fiscal Calendar Hierarchy].[Fiscal Week].MEMBERS,
(ParallelPeriod([Time].[Fiscal Calendar Hierarchy].[Fiscal Year]),
[TY Net Sales Amount])
)
'

MEMBER [Time].[Fiscal Calendar Hierarchy].[All Fiscal Periods].[ Grand Total]

AS 'AGGREGATE( EXISTING INTERSECT( { { EXTRACT( { [Time].[Fiscal Calendar Hierarchy].[Fiscal Week].&[2006010101],

[Time].[Fiscal Calendar Hierarchy].[Fiscal Week].&[2006010102], [Time].[Fiscal Calendar Hierarchy].[Fiscal

Week].&[2006010103], [Time].[Fiscal Calendar Hierarchy].[Fiscal Week].&[2006010104] }, [Time].[Fiscal Calendar Hierarchy] ) }

}, { [Time].[Fiscal Calendar Hierarchy].[Fiscal Week].&[2006010101], [Time].[Fiscal Calendar Hierarchy].[Fiscal

Week].&[2006010102], [Time].[Fiscal Calendar Hierarchy].[Fiscal Week].&[2006010103], [Time].[Fiscal Calendar

Hierarchy].[Fiscal Week].&[2006010104] } ) )', SOLVE_ORDER = 1000

SELECT { LastYearSales } ON COLUMNS,

{ { [Time].[Fiscal Calendar Hierarchy].[Fiscal Week].&[2006010101], [Time].[Fiscal Calendar Hierarchy].[Fiscal

Week].&[2006010102], [Time].[Fiscal Calendar Hierarchy].[Fiscal Week].&[2006010103], [Time].[Fiscal Calendar

Hierarchy].[Fiscal Week].&[2006010104] }, ( [Time].[Fiscal Calendar Hierarchy].[All Fiscal Periods].[ Grand Total] ) } ON

ROWS

FROM [Sales]

CELL PROPERTIES VALUE, FORMATTED_VALUE, CELL_ORDINAL, ACTION_TYPE

========

OUTPUT

LastYearSales
Week 1 100
Week 2 200
Week 3 300
Week 4 400
Grand Total 50000 -> This is not the sum of the four weeks which should be 900. Instead it is sum across all weeks across all years in the time dimension. So effectively, the Existing statement is not getting the correct context (which is

the set of four fiscal weeks) while processing the aggregate (grand total) row. The only part of the code above that we can change is the definition of the calculated measure LastYearSales. The remaining is generated by proclarity.

We followed the recommendations by Mosha in his blog,
http://sqljunkies.com/WebLog/mosha/archive/2007/01/13/multiselect_parallelperiod.aspx

There is a problem with how Proclarity generates MDX in this case. (In fact I just reviewed very similar scenario this week). This is actually not multiselect scenario for which I wrote blog, but Visual Totals scenario, which is harder. The calculated member with Aggregate is not in the WHERE clause, therefore context for current coordinate is not set, and EXISTING in the definition of calculated member does nothing. Sorry, but the solution for multiselect won't work for Visual Totals.