简体   繁体   English

如何在SSAS / MDX中为用户定义的层次结构中的级别获取“(所有)”值

[英]How to get an “(all)” value for a level in a user defined hierarchy in SSAS/MDX

I am trying to work out how I can get a total for a level in a user defined hierarchy. 我试图弄清楚如何获得用户定义层次结构中某个级别的总计。 For example if I do (using Adventure works here): 例如,如果我这样做(在此处使用Adventure工作):

SELECT [Measures].[Internet Sales Amount] ON 0,
([Date].[Calendar Year].ALLMEMBERS * [Date].[Month of Year].ALLMEMBERS) ON 1
FROM [Adventure Works]

I get totals for each pair of year/month values. 我得到每一对年/月值的总计。

How can I rewrite this query using the Calendar user hierarchy in the Date dimensions? 如何使用“日期”维度中的“日历”用户层次结构重写此查询? Eg something like: 例如:

SELECT [Measures].[Internet Sales Amount] ON 0,
([Date].[Calendar].[Year] * [Date].[Calendar].[Month]) ON 1
FROM [Adventure Works]

You can use 您可以使用

SELECT [Measures].[Internet Sales Amount] ON 0,
Hierarchize([Date].[Calendar].[Calendar Year] + [Date].[Calendar].[Month]) ON 1
FROM [Adventure Works]

This will show you each year containing its value (which is the sum of the months contained in it) before the months. 这将在月份之前向您显示包含其值(即其中包含的月份的总和)的每年。

The + is the short form of Union in MDX, and Hierarchize sorts a set in hierarchical order, which means parents before children. +是MDX中Union的缩写形式,并且HierarchizeHierarchize对集合进行排序,这意味着父级先于子级。

And if you want something similar to your first result, the closest thing I can imagine would be via calculated measures like this: 而且,如果您希望获得与第一个结果相似的结果,那么我能想到的最接近的结果将是通过这样的计算得出的度量得出的:

WITH Member Measures.Year AS
            IIf([Date].[Calendar].CurrentMember.Level IS [Date].[Calendar].[Calendar Year],
                [Date].[Calendar].CurrentMember.Name,
                Ancestor([Date].[Calendar].CurrentMember, [Date].[Calendar].[Calendar Year]).Name
               )
     Member Measures.Month AS
            IIf([Date].[Calendar].CurrentMember.Level IS [Date].[Calendar].[Month],
                [Date].[Calendar].CurrentMember.Name,
                'All Months'
               )
SELECT {
        Measures.Year,
        Measures.Month,
        [Measures].[Internet Sales Amount]
       }
       ON 0,
Hierarchize([Date].[Calendar].[Calendar Year] + [Date].[Calendar].[Month]) ON 1
FROM [Adventure Works]

Note that calculated members need not return numbers, they can as well return strings. 请注意,计算所得成员不必返回数字,它们也可以返回字符串。

Using allmembers as you have it should return you the ALL line and then each year and each month. 按原样使用allmembers应该返回ALL行,然后返回每年和每月。 If you are interested in only the all line you can change you query to: 如果您只对所有行感兴趣,则可以将查询更改为:

SELECT [Measures].[Internet Sales Amount] ON 0,
([Date].[Calendar Year] * [Date].[Month of Year]) ON 1
FROM [Adventure Works]

Notice how it is specifying only the Dimension and the hierarchy. 请注意,它是如何仅指定维和层次结构的。

If you wanted to get the data without the all line use the following: 如果要获取所有行都没有的数据,请使用以下命令:

SELECT [Measures].[Internet Sales Amount] ON 0,
([Date].[Calendar Year].children * [Date].[Month of Year].children) ON 1
FROM [Adventure Works]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM