Showing posts with label sample. Show all posts
Showing posts with label sample. Show all posts

Monday, March 19, 2012

MDX's ORDER Function

Hi

I'm trying to order rows returned by a MDX query using ORDER function. It seems that I don't use it properly. Here is the query from the sample AS Database, AdventureWork.

WITH MEMBER [Measures].DIFF AS
'([Customer].[Country].CURRENTMEMBER, [Measures].[Internet Sales Amount])
-
([Customer].[Country].&[Australia], [Measures].[Internet Sales Amount])'
SELECT [Measures].DIFF ON COLUMNS,
ORDER([Customer].[Country].MEMBERS, [Measures].DIFF, BDESC) ON ROWS
FROM [Adventure Works]

what it returns is:

All Customers $20,297,676.64
United States $328,788.93
Australia $0.00
United Kingdom ($5,669,288.37)
Germany ($6,166,688.25)
France ($6,416,982.87)
Canada ($7,083,155.72)

I expected to see "Australia" at the end of the list and "All Customers" on top of it.
Any Idea?

Thanks in advance,
AmirThe results look correct to me. Why do you expect Australia at the end ? It's DIFF is 0 which is bigger then negative diffs of other countries.|||Sorry about that.
I didn't realize there is a bracket arround negative numbers.

Thanks

MDX: Percentage-to-totals with subcubes (AW code sample)

I need to create a calculation that gives me the percentage of a members value relative to the total. My problem is that I cannot make it work when my query is using a subcube in the from clause. The calculated member is simply not able to look outside the defined subcube.

In other words - the following query works as expected:

WITH

MEMBER [Measures].[Test] AS

[Measures].[Internet Sales Amount]/(ROOT([Product]),[Measures].[Internet Sales Amount]),

NON_EMPTY_BEHAVIOR = [Measures].[Internet Sales Amount],

FORMAT_STRING = "#.##"

SELECT {[Measures].[Internet Sales Amount], [Measures].[Test]} ON 0,

NON EMPTY [Product].[Subcategory].MEMBERS ON 1

FROM [Adventure Works]

WHERE [Product].[Product Line].&[R]

But the following does not. It simply reports the percentage relative to the total in the current subcube, which is not what I want.

WITH

MEMBER [Measures].[Test] AS

[Measures].[Internet Sales Amount]/(ROOT([Product]),[Measures].[Internet Sales Amount]),

NON_EMPTY_BEHAVIOR = [Measures].[Internet Sales Amount],

FORMAT_STRING = "#.##"

SELECT {[Measures].[Internet Sales Amount], [Measures].[Test]} ON 0,

NON EMPTY [Product].[Subcategory].MEMBERS ON 1

FROM

(SELECT [Product].[Product Line].&[R] ON 0 FROM [Adventure Works])

I thought a calculated member should be able to 'look outside' the subcube in the last query and return the value I want?! After all, I am trying (with the ROOT() function) to refer to the highest possible level in the product dimension.

Why don't I just use the first query then, if it gives me the result I want? I can't, since the client application submitting the query is using subcubes to restrict the returned results.

Does anybody have an idea what's going on?|||

The behaviour of calculated members has never properly been documented wrt subcubes, but I can believe that what you're seeing is intended functionality. After all, while you might want to be able to refer to members which don't exist in the current subcube in a calculated member (for example to make year-to-date calculations return sensible values) what you're doing is referring to members which do exist in the subcube, and I can see why it makes sense to see the totals summed up for the members selected in the subcube here. After all, isn't it equally likely that someone would want what you get in your example query, the percentage relative to the current subcube?

HTH,

Chris

|||

Thanks Chris

Well - you're right. The behavior could be what is expected by users in some cases. However, in my case I really need the total, which is unaffected by the subcube in the FROM clause. How can I obtain this then? Is my only option to create a "shadow" dimension (which is really just a copy of the product dimension) and reference the root of this?

|||

What do you need to do, exactly? Is there any reason why you can't use the WHERE clause?

Chris

|||

Well - if I could, I would certainly use a WHERE clause, but my client application (TARGIT) uses subselects to restrict the query results. That might change, but in the meantime I need to try and make my calculated members robust wrt. subselects.

I need to do the following: [Measures].[Internet Sales Amount]/([Measures].[Internet Sales Amount], ROOT([Product]))

The tuple ([Measures].[Internet Sales Amount], ROOT([Product])) needs to be affected by selections on all other dimensions than the Product dimension. If for example the cube is sliced by year 2005, ([Measures].[Internet Sales Amount], ROOT([Product])) should return the total Internet Sales Amount for 2005 regardless of any selection on the Product dimension - and this is what is possible with the WHERE clause.

|||

I suppose the solution would be to work with the fact that you can look along a level to see members which aren't there. Here's a rough, but working example of the approach I'm thinking of:

WITH

MEMBER [Measures].[Test] AS

[Measures].[Internet Sales Amount]/

AGGREGATE(

[Product].[Product].[Product].MEMBERS

, [Measures].[Internet Sales Amount]

),

NON_EMPTY_BEHAVIOR = [Measures].[Internet Sales Amount],

FORMAT_STRING = "#.##"

MEMBER [Measures].[Test2] AS

[Measures].[Internet Sales Amount]/(ROOT([Product]),[Measures].[Internet Sales Amount]),

NON_EMPTY_BEHAVIOR = [Measures].[Internet Sales Amount],

FORMAT_STRING = "#.##"

SELECT {[Measures].[Internet Sales Amount], [Measures].[Test], [Measures].[Test2]} ON 0,

NON EMPTY [Product].[Subcategory].MEMBERS ON 1

FROM

(SELECT [Product].[Product Line].&[R] ON 0 FROM [Adventure Works])

It only seems to work when you aggregate the members of the leaf level of the key attribute though - I'm sure there's a good reason for this but I'll have to sit down and work out why when I have some spare time...

Chris

|||

Thanks a lot Chris

It's not the most performant of solutions, since the key attribute I now need to aggregate has around 50,000 members. But it works!

|||

Good news! It seems that this issue has been solved in SP2. It is now possible to compute the correct percentage-to-total with the subcube query.

This must have been one of the things that have been changed around sub-selects in SP2

|||

Yes - there was a change in subselect Visual Totals behavior in SP2. In a nutshell instead of just checking granularities to decide whether or not to apply Visual Totals, SP2 now checks coordinate overwrite history. I will try to put a more detailed blog entry about it.

Mosha

MDX: Percentage-to-totals with subcubes (AW code sample)

I need to create a calculation that gives me the percentage of a members value relative to the total. My problem is that I cannot make it work when my query is using a subcube in the from clause. The calculated member is simply not able to look outside the defined subcube.

In other words - the following query works as expected:

WITH

MEMBER [Measures].[Test] AS

[Measures].[Internet Sales Amount]/(ROOT([Product]),[Measures].[Internet Sales Amount]),

NON_EMPTY_BEHAVIOR = [Measures].[Internet Sales Amount],

FORMAT_STRING = "#.##"

SELECT {[Measures].[Internet Sales Amount], [Measures].[Test]} ON 0,

NON EMPTY [Product].[Subcategory].MEMBERS ON 1

FROM [Adventure Works]

WHERE [Product].[Product Line].&[R]

But the following does not. It simply reports the percentage relative to the total in the current subcube, which is not what I want.

WITH

MEMBER [Measures].[Test] AS

[Measures].[Internet Sales Amount]/(ROOT([Product]),[Measures].[Internet Sales Amount]),

NON_EMPTY_BEHAVIOR = [Measures].[Internet Sales Amount],

FORMAT_STRING = "#.##"

SELECT {[Measures].[Internet Sales Amount], [Measures].[Test]} ON 0,

NON EMPTY [Product].[Subcategory].MEMBERS ON 1

FROM

(SELECT [Product].[Product Line].&[R] ON 0 FROM [Adventure Works])

I thought a calculated member should be able to 'look outside' the subcube in the last query and return the value I want?! After all, I am trying (with the ROOT() function) to refer to the highest possible level in the product dimension.

Why don't I just use the first query then, if it gives me the result I want? I can't, since the client application submitting the query is using subcubes to restrict the returned results.

Does anybody have an idea what's going on?|||

The behaviour of calculated members has never properly been documented wrt subcubes, but I can believe that what you're seeing is intended functionality. After all, while you might want to be able to refer to members which don't exist in the current subcube in a calculated member (for example to make year-to-date calculations return sensible values) what you're doing is referring to members which do exist in the subcube, and I can see why it makes sense to see the totals summed up for the members selected in the subcube here. After all, isn't it equally likely that someone would want what you get in your example query, the percentage relative to the current subcube?

HTH,

Chris

|||

Thanks Chris

Well - you're right. The behavior could be what is expected by users in some cases. However, in my case I really need the total, which is unaffected by the subcube in the FROM clause. How can I obtain this then? Is my only option to create a "shadow" dimension (which is really just a copy of the product dimension) and reference the root of this?

|||

What do you need to do, exactly? Is there any reason why you can't use the WHERE clause?

Chris

|||

Well - if I could, I would certainly use a WHERE clause, but my client application (TARGIT) uses subselects to restrict the query results. That might change, but in the meantime I need to try and make my calculated members robust wrt. subselects.

I need to do the following: [Measures].[Internet Sales Amount]/([Measures].[Internet Sales Amount], ROOT([Product]))

The tuple ([Measures].[Internet Sales Amount], ROOT([Product])) needs to be affected by selections on all other dimensions than the Product dimension. If for example the cube is sliced by year 2005, ([Measures].[Internet Sales Amount], ROOT([Product])) should return the total Internet Sales Amount for 2005 regardless of any selection on the Product dimension - and this is what is possible with the WHERE clause.

|||

I suppose the solution would be to work with the fact that you can look along a level to see members which aren't there. Here's a rough, but working example of the approach I'm thinking of:

WITH

MEMBER [Measures].[Test] AS

[Measures].[Internet Sales Amount]/

AGGREGATE(

[Product].[Product].[Product].MEMBERS

, [Measures].[Internet Sales Amount]

),

NON_EMPTY_BEHAVIOR = [Measures].[Internet Sales Amount],

FORMAT_STRING = "#.##"

MEMBER [Measures].[Test2] AS

[Measures].[Internet Sales Amount]/(ROOT([Product]),[Measures].[Internet Sales Amount]),

NON_EMPTY_BEHAVIOR = [Measures].[Internet Sales Amount],

FORMAT_STRING = "#.##"

SELECT {[Measures].[Internet Sales Amount], [Measures].[Test], [Measures].[Test2]} ON 0,

NON EMPTY [Product].[Subcategory].MEMBERS ON 1

FROM

(SELECT [Product].[Product Line].&[R] ON 0 FROM [Adventure Works])

It only seems to work when you aggregate the members of the leaf level of the key attribute though - I'm sure there's a good reason for this but I'll have to sit down and work out why when I have some spare time...

Chris

|||

Thanks a lot Chris

It's not the most performant of solutions, since the key attribute I now need to aggregate has around 50,000 members. But it works!

|||

Good news! It seems that this issue has been solved in SP2. It is now possible to compute the correct percentage-to-total with the subcube query.

This must have been one of the things that have been changed around sub-selects in SP2

|||

Yes - there was a change in subselect Visual Totals behavior in SP2. In a nutshell instead of just checking granularities to decide whether or not to apply Visual Totals, SP2 now checks coordinate overwrite history. I will try to put a more detailed blog entry about it.

Mosha

Friday, March 9, 2012

MDX Sample Application...

Does anyone know where you can download the MDX sample application from?

if you are running Analysis Services 2005, SQL Server Management Studio is the new query tool.

You can connect to Analysis Services 2005 and write MDX queries here.

HTH

Thomas Ivarsson

|||

As far as I know, MDX Sample is not available as a public download. It’s sample code that ships with our Analysis Services 2000 product.

--Artur

|||

Hi Artur

The SQL Server 2000 Samples (with MDX sample application) are still free to download

http://www.microsoft.com/downloads/details.aspx?familyid=7824ba50-3e29-45cf-8c02-5597c014a707&displaylang=en

One of the great benefits of the MDX sample application is a possibility to set connection string options.

it is impossible In SqlWb :-(

MDX Reference Book

What would you recommend for a good MDX book ?
specifically, for syntax, data structures and sample code.
thx
CHow about

http://www.sqlteam.com/store.asp

MDX question

Hi there,
In SQL Server 2000 we use to have Sample (MDX tools) application
That you can execute an MDX query
Where in SQL Server 2005 I can write an MDX quiry and execute?
Thanks,
Oded DrorSql Server Managment studio. File->New->MDX query ...
MC
"Oded Dror" <odeddror@.cox.net> wrote in message
news:OYyWckJiGHA.4776@.TK2MSFTNGP05.phx.gbl...
> Hi there,
> In SQL Server 2000 we use to have Sample (MDX tools) application
> That you can execute an MDX query
> Where in SQL Server 2005 I can write an MDX quiry and execute?
> Thanks,
> Oded Dror
>