3
votes

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.

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:

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.

But Count1 always stays equal to 1.

1

1 Answers

1
votes

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 pivot table generates query like this:

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.