简体   繁体   English

MDX:计算在过滤器中选择的成员数

[英]MDX: count number of members selected in filter

I have one dimension that I want to put into filter, and created calculated member that should dynamically show number of selected members from the dimension. 我有一个要放入过滤器的维度,并创建了计算所得的成员,该成员应动态显示该维度中所选成员的数量。

The dimension does not have an All member. 该维度没有All成员。

So this is my attempt 这是我的尝试

with member [Measures].[Count1] as count(existing(([MyDimension].[MyDimensionHierarchy].members)))

select  [Measures].[Count1] on 0
from [MyCube] --  gives me 1 

and this one will give me 2 which is correct: 这将给我2个正确的答案:

with member [Measures].[Count1] as count(existing(([MyDimension].[MyDimensionHierarchy].members)))

select  [Measures].[Count1] on 0
from [MyCube]
where ({[MyDimension].[MyDimensionHierarchy].[Member1], [MyDimension].[MyDimensionHierarchy].[Member2]})

But, the problem is that when I create calculated member with the formula above, and drag Count1 to the Excel pivot table, and drag MyDimension as filter, and when I do multi-select of the dimension members, I want the count to dynamically change as I change number of members that are selected. 但是, 问题在于,当我使用上述公式创建计算所得的成员,并将Count1拖到Excel数据透视表中,并将MyDimension作为过滤器时,当我对维度成员进行多选时,我希望计数动态变化当我更改所选成员的数量时。

But Count1 always stays equal to 1. 但是Count1始终等于1。

In a meantime I have found an answer: 在此期间,我找到了答案:

The query that I wrote in the question actually is not the query that Excel pivot table sends to the cube. 我在问题中编写的查询实际上不是Excel数据透视表发送到多维数据集的查询。 Excel pivot table generates query like this: Excel数据透视表生成如下查询:

SELECT  FROM (SELECT ({[MyDimension].[MyDimensionHierarchy].[Member1],[MyDimension].[MyDimensionHierarchy].[Member2]}) ON COLUMNS  
FROM [MyCube]) 
WHERE ([Measures].[Count1]) 

The way this should be done is by using dynamic set that contains filtered members: 应使用包含过滤成员的动态集来完成此操作:

create dynamic set [SelectedMembers] as existing( [MyDimension].[MyDimensionHierarchy].members )

And then: 接着:

create member Measures.SelectedMembersCount as count([SelectedMembers])

So this set dynamically changes as different members are selected in the filter and SelectedMembersCount is dynamically changed along the way. 因此,此集合会随着在过滤器中选择不同的成员而动态变化,并且SelectedMembersCount会随之动态变化。

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

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