I am trying to replicate the following sql statement into MDX so that I can create a calculated member in the cube using the base loaded members instead of having to calculate it outside the cube in the table and then loading it
SUM(CASE WHEN ((A.SALES_TYPE_CD = 1) AND (A.REG_SALES=0))
THEN A.WIN_SALES
ELSE 0
END) AS Z_SALES
I am currently loading SALES_TYPE_CD
as a dimension and REG_SALES
and WIN_SALES
as measures.
I also have a few other dimensions in the cube but for simplicity, lets just say I have 2 other dimensions, LOCATION
and ITEM
The dimension has LOCATION
has 3 levels, "Region"->"District"->"Store"
, ordered from top to bottom level.
The dimension has ITEM
has 3 levels, "CLASS"->"SUBCLASS"->"SKU"
, ordered from top to bottom level.
The dimension has SALES TYPE
has 2 levels, "SALES_TYPE_GROUP"->"SALES_TYPE_CD"
, ordered from top to bottom level.
I know that I cannot create a simple calculated member in the cube which crossjoins the "SALES_TYPE" dimension with another dimension to get the answer I want.
I would think that it would be a more complicated MDX statement something like :
CREATE MEMBER CURRENTCUBE.[Measures].[Z_Sales]
AS 'sum(filter(crossjoin(leaves(), [Sales Type].[Sales Type].
[Sales_Type_CD].&[1]), [Measures].[REG_SALES]=0),[Measures].
[WIN_SALES])',
FORMAT_STRING = '#,#',
VISIBLE = 1 ;
But this does not seem to return the desired result. What would be the proper MDX code to generate the desired result?