MDX 按维度属性计算的成员过滤器
我想创建一个计算成员并按维度过滤它。这是有效的示例:
(
[Policy].[Policy Status].&[Void],
[Policy].[Tran Type].&[Renewal],
[Measures].[FK Policy Distinct Count]
)
但是如果我想像这样过滤它,
(
[Policy].[Policy Status].&[Void],
[Policy].[Policy Status].&[Policy],
[Measures].[FK Policy Distinct Count]
)
那么它就不起作用。它表示相同的层次结构在元组中显示多次。
另一件事是,如何排除行?这是这个想法...
(
![Policy].[Policy Status].&[Void],
![Policy].[Policy Status].&[Policy],
[Measures].[FK Policy Distinct Count]
)
I want to create a calculated member and filter it by dimension. This is WORKING example:
(
[Policy].[Policy Status].&[Void],
[Policy].[Tran Type].&[Renewal],
[Measures].[FK Policy Distinct Count]
)
But if I want to filter it like this
(
[Policy].[Policy Status].&[Void],
[Policy].[Policy Status].&[Policy],
[Measures].[FK Policy Distinct Count]
)
Than it's NOT working. It says that same hierarchy is showing multiple times in the tuple.
Another thing is, how to exclude rows? Here's the idea...
(
![Policy].[Policy Status].&[Void],
![Policy].[Policy Status].&[Policy],
[Measures].[FK Policy Distinct Count]
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,了解 MDX 语法及其与 元组、成员和集合。
元组
使用括号表示元组:
元组只能包含来自任何层次结构的单个成员。
集
要从同一层次结构中的多个成员检索结果,您必须查询集。 MDX 集用大括号表示:
根据定义,集是,
因此,如果您希望针对这两个成员查询
[FK Policy Distinct Count]
度量,则该集合的元组必须各自包含该度量:为了简化此表达式,可以 交叉连接两个不同维度的集合:
排除行
现在我们可以定义集合了,是时候删除一些成员了从一。在您的示例中,听起来您想要从一个级别开始(对于 MDX 引擎来说,该级别只是多维数据集中的预定义集,其中包括层次结构中该级别的每个成员),并排除某些成员。 MDX 有很多对集合进行操作的函数,我们将使用
EXCEPT
。EXCEPT
函数采用两个参数,第一个参数设置为从中删除,第二个是应该从第一个中删除的集合。它返回一个集合。在此示例中,我将假设
[Policy].[Policy Status]
是一个属性层次结构,并且其唯一级别的唯一名称为[Policy].[Policy Status ].[政策状态]
。这将返回
[Policy].[Policy Status].[Policy Status]
级别的每个成员,[Policy].[Policy Status].&[Void]
除外code> 和[策略].[策略状态].&[策略]
。为了获得有用的结果,我们可以通过度量交叉连接结果:
将集合用作单个成员
集合很好,但有时我们想要的只是将它们视为单个成员,就像在计算的成员要求中一样。为此,我们需要使用聚合函数。聚合函数接受一个集合并返回代表整个集合的成员。
其中有很多,使用正确的一个取决于多维数据集中存储的数据:
MIN
、MAX
、COUNT
和SUM
是其中的一些(请参阅MDX 函数参考<中的“数字函数” /a> 以获得更完整的列表)。在此示例中,我将假设您的维度通过使用 SUM 进行聚合:在这里,我已将要聚合的度量作为第二个参数传递给 SUM。
MDX 是一种复杂的语言,支持许多常见和不常见的集合运算。如果您还没有这样做,我建议您花时间阅读在线可用的文档,或者给自己找一本好的 MDX 书籍。有很多东西需要知道:)
<3
First, it's important to understand the MDX syntax, and how it related to the concepts of tuples, members and sets.
Tuples
Using parentheses denotes a tuple:
A tuple can only include a single member from any hierarchy.
Sets
To retrieve results from multiple members in the same hierarchy, you must query for a set. An MDX set is denoted by braces:
A set is, by definition,
So, if you wish to query for the
[FK Policy Distinct Count]
measure against both of those members, the set's tuples must each include the measure:To simplify this expression, it is possible to crossjoin two sets of different dimensionality:
Excluding rows
Now that we can define sets, it's time to remove some members from one. In your example, it sounds like you want to start with a level (which, to the MDX engine, is just a predefined set in the cube which includes every member at that level of the hierarchy), and exclude certain members. MDX has lots of functions that operate on sets, and we're going to use
EXCEPT
.The
EXCEPT
function takes two parameters, the first being the set to remove from, and the second being the set which should be removed from the first. It returns a set.In this example, I'm going to assume
[Policy].[Policy Status]
is an attribute hierarchy, and that its sole level has the Unique Name of[Policy].[Policy Status].[Policy Status]
.This will return every member from the
[Policy].[Policy Status].[Policy Status]
level, except for[Policy].[Policy Status].&[Void]
and[Policy].[Policy Status].&[Policy]
.To get useful results, we can cross-join the result by a measure:
Using a set as a single member
Sets are nice, but sometimes all we want from them is to treat them as a single member, as in your calculated member requirement. To do this, we need to use an aggregation function. Aggregation functions take in a set and return a member that represents the entire set.
There are a number of these, and the right one to use depends on the data stored in your cube:
MIN
,MAX
,COUNT
, andSUM
are some of them (see "Numeric Functions" in the MDX Function reference for a more complete list). In this example, I'll assume your dimension aggregates by using SUM:Here, I have passed the measure to be aggregated as the second parameter to SUM.
MDX is a complex language which supports many common and uncommon set operations. If you haven't already, I advise taking the time to read over the documentation available online, or grab yourself a good MDX book. There's a lot to know :)
<3
试试这个语法:
Try this syntax: