开发者

Ordering By a Hierarchy Level?

开发者 https://www.devze.com 2023-04-05 05:08 出处:网络
I have used the ADventureWorksDW 2008 R2 SSAS db to recreate my problem.I have two queries, but one doesn\'t work and I\'d like to understand why.The first is not using a user hierarchy, and the secon

I have used the ADventureWorksDW 2008 R2 SSAS db to recreate my problem. I have two queries, but one doesn't work and I'd like to understand why. The first is not using a user hierarchy, and the second which doesn't sort correctly, is using he hierarchy [Sales Territory].

It is important for me to get the second query to behave properly, because I would like to remove the [Sales Territory].[Sales Territory Country] attribute from the dimension. Often times if I have placed an attribute such as Country into a hierarchy, then I remove the attribute from the dimension, so that it is only available under the hierarchy (following recommended best practices, to avoid user confusion arising form the attribute appearing in multiple places in the dimension).

So how can I make the second query behave like the first, to sort the countries correctly?

//Works
Select 
{
  ([Measures].[Reseller Sales Amount])
} on columns
,
non empty 
  Order(
    ([Sales Territory].[Sales Territory Country].[Sales Territory Country].Mem开发者_StackOverflowbers),
    [Sales Territory].[Sales Territory Country].CurrentMember.Name,DESC)  on rows
From [Adventure Works]
Where ( [CY 2007] )

GO

//Doesn't work in that countries aren't sorted
Select 
{
  ([Measures].[Reseller Sales Amount])
} on columns
,
non empty 
  Order(
    ([Sales Territory].[Sales Territory].[Country].Members),
    [Sales Territory].[Sales Territory].CurrentMember.Name,DESC)  on rows
From [Adventure Works]
Where ( [CY 2007] )


There is another approach you can use, to avoid the user confusion from having both the attribute and the hierarchy available.

This is to mark the the underlying attribute as hidden (not visible), and then include it in a hierarchy (which may just be a single-level hierarchy). This gives you all the advantages of having the hierarchy available without the name clash. It's an approach I've used successfully on MSAS projects in the past.

Doesn't quite answer your ordering question but it hopefully does give you another option to explore.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号