DanUp


I need to create MDX for the following logic: After ranking Lenders by Loan Amount and displaying loan count (see below), calculate the following add'l displayed fields. Dollars Behind 1st, % of Dollars Behind 1st, and Count Behind First (which will sometimes be a negative number, since lender with highest amounts may not have highest count).

How do I build the MDX expression (query ) to support the last three calc'd fields

Spreadsheet Example Logic:

Lender Loan Amts Count $ Behind 1st % (of $) Behind 1st Count Behind 1st

A $100,000,000 100 n/a n/a n/a

B $ 70,000,000 120 $30,000,000 30% (20)

C $ 60,000,000 50 $40,000,000 50% 50

----------------------------------------------------------------------------------------------------------------

Thank you in advance for help.

Daniel Upton




Re: Ranking by One Field, Displaying Multiple Fields

Deepak Puri


Here's a sample Adventure Works query, using Sales Amount and Order Quantity measures:

Code Snippet

with

set [OrderedCategories] as

Order([Product].[Category].[Category]

- {[Product].[Category].[Bikes]},

[Measures].[Sales Amount], BDESC)

Member [Measures].[$ Behind 1st] as

iif([Product].[Category].CurrentMember

is [OrderedCategories].Item(0), Null,

([Measures].[Sales Amount],

[OrderedCategories].Item(0))

- [Measures].[Sales Amount]),

FORMAT_STRING = 'Currency'

Member [Measures].[% Behind 1st] as

[Measures].[$ Behind 1st] /

([Measures].[Sales Amount],

[OrderedCategories].Item(0)),

FORMAT_STRING = 'Percent'

Member [Measures].[Orders Behind 1st] as

iif([Product].[Category].CurrentMember

is [OrderedCategories].Item(0), Null,

([Measures].[Order Quantity],

[OrderedCategories].Item(0))

- [Measures].[Order Quantity]),

FORMAT_STRING = '#,#;(#,#)'

select

{[Measures].[Sales Amount],

[Measures].[Order Quantity],

[Measures].[$ Behind 1st],

[Measures].[% Behind 1st],

[Measures].[Orders Behind 1st]} on 0,

[OrderedCategories] on 1

from [Adventure Works]

------------------------------------------------------------------------

Sales Amount Order Quantity $ Behind 1st % Behind 1st Orders Behind 1st
Components $11,799,076.66 49,027 (null) (null) (null)
Clothing $2,117,613.45 73,598 $9,681,463.21 82.05% (24,571)
Accessories $1,272,057.89 61,931 $10,527,018.77 89.22% (12,904)







Re: Ranking by One Field, Displaying Multiple Fields

DanUp

Thank you, Deepak. Here is how it looks right now in my cube.

The ORDER fn works for me, but the three calc'd fields are returning errors, and I cannot find a code discrepancy:

CODE ADAPTED TO OUR CUBE:

with

set [LenderRankByLoanVolume] as

Order([Lender Name].[Master - DBA - Deed Stamp].[Lender Master Entity]

- {

[Lender Name].[Master - DBA - Deed Stamp].[Lender Master Entity].[Miscellaneous]

},

[Measures].[Loan Amount], DESC)

Member [Measures].[Behind 1st $] as

iif (

[Lender Name].[Master - DBA - Deed Stamp].[Lender Master Entity].CurrentMember

IS [LenderRankByLoanVolume].Item(0), Null,

( [Measures].[Loan Amount],

[LenderRankByLoanVolume].Item(0)

)

- [Measures].[Loan Amount]

),

FORMAT_STRING = 'Currency'

Member [Measures].[Behind 1st %] as

[Measures].[Behind 1st $] /

([Measures].[Loan Amount],

[LenderRankByLoanVolume].Item(0)),

FORMAT_STRING = 'Percent'

Member [Measures].[Behind 1st Count] as

iif (

[Lender Name].[Master - DBA - Deed Stamp].[Lender Master Entity].CurrentMember

is [LenderRankByLoanVolume].Item(0), Null,

( [Measures].[Loan Count],

[LenderRankByLoanVolume].Item(0)

)

- [Measures].[Loan Count]

),

FORMAT_STRING = '#,#;(#,#)'

SELECT

{[Measures].[Loan Amount],

[Measures].[Loan Count],

[Measures].[Behind 1st $],

[Measures].[Behind 1st %],

[Measures].[Behind 1st Count]} ON 0,

[LenderRankByLoanVolume] ON 1

FROM [Sales_Loans_Cube]

-----------------------------------------------------------

Returns Results:

Loan Amount Loan Count Behind 1st $ Behind 1st % Behind 1st Count
Lender X $1,612,873,402 27,359 #Error #Error #Error
Lender D $764,804,224 1,149 #Error #Error #Error
Lender A $731,280,531 15,811 #Error #Error #Error
Lender Q $708,404,260 27,105 #Error #Error #Error
etc¡­

Do you see any code discrepancy Would additional info or code help

Returns Messages:

Parsing the query ...

Obtained object of type: Microsoft.AnalysisServices.AdomdClient.CellSet

Parsing complete






Re: Ranking by One Field, Displaying Multiple Fields

Deepak Puri

One obvious issue is that .CurrentMember should be applied to a hierarchy, not to a level, so:

[Lender Name].[Master - DBA - Deed Stamp].[Lender Master Entity].CurrentMember

should probably be:

[Lender Name].[Master - DBA - Deed Stamp].CurrentMember






Re: Ranking by One Field, Displaying Multiple Fields

DanUp

Yes, that creates a very cool MDX query. Thank you, Deepak. Sadly, our otherwise-slick OLAP front-end product (Strategy Companion) does not accept MDX Queries directly (only MDX Expressions). So (and I'm kind of begging now)...

How can this query be converted into either...

(a) A series of separate MDX expressions, or...

(b) something like an "MDX shell" dimension, (perhaps with a single attribute and with expression implemented as a member of that attribute.

Here is what I've produced so far...

CREATE SET CURRENTCUBE.[Lender Rank By Volume]

AS Order([Lender Name].[Master - DBA - Deed Stamp].[Lender Master Entity]

- {

[Lender Name].[Master - DBA - Deed Stamp].[Lender Master Entity].[Miscellaneous]

},

[Measures].[Loan Amount], DESC) ;

CREATE MEMBER CURRENTCUBE.[MEASURES].[Behind 1st $]

AS iif([Lender Name].[Master - DBA - Deed Stamp].CurrentMember

IS [Lender Rank By Volume].Item(0), Null,

( [Measures].[Loan Amount],

[LenderRankByVolume].Item(0)

)

- [Measures].[Loan Amount]

),

FORMAT_STRING = "$#,##0",

VISIBLE = 1;

(I've not created the other two members yet, since the above one throws an error).

When browsed in OWC, it disallows me from dropping the set as a column in OWC browser, and returns an error of #VALUE! for the "Behind 1st $" member.

What's wrong here





Re: Ranking by One Field, Displaying Multiple Fields

Deepak Puri

Looks like you have a typo in the measure - [LenderRankByVolume] is not the same as [Lender Rank By Volume].






Re: Ranking by One Field, Displaying Multiple Fields

DanUp

Yes, you're right. However, even with this change, it still malfunctions as stated in my last post. Any ideas why





Re: Ranking by One Field, Displaying Multiple Fields

Deepak Puri

When you say: When browsed in OWC, it disallows me from dropping the set as a column in OWC browser, and returns an error of #VALUE! for the "Behind 1st $" member, are you referring to the cube browser in BIDS (which uses OWC) If so, is there more information on the error, when you double-click the cell with #VALUE I don't see an obvious problem on inspecting the code; but if you can reproduce this issue in Adventure Works, it'll be easier for others to help.