Here is an MDX calculated measure that uses trick that you want:
I used my base, so please substitute [Create Date].[Create Date].[Year].&[2014]
with your own set and [Create Date].[Create Date].[Month]
with your level of dimension [Cow]
. Here is a standard 'Year-Month-Day' dimension.
CREATE MEMBER CURRENTCUBE.[Measures].[TestAgg]
AS
IIF(
Intersect(
[Create Date].[Create Date].CurrentMember
,Exists(
Descendants(
[Create Date].[Create Date].[Year].&[2014]
,[Create Date].[Create Date].[Month]
,SELF_BEFORE_AFTER
)
)
).Count > 0
,[Measures].[Count]
,IIF(
[Create Date].[Create Date].CurrentMember is [Create Date].[Create Date].[All]
,AGGREGATE(
{[Create Date].[Create Date].[Year].&[2014]}
,[Measures].[Count])
,null
)
),
VISIBLE = 1;
Here is some explanation:
- I used
Descendants
to organize the set of necessary members.
Intersect
is used to understand whether the current member of the dimension is under this filter condition.
- Then the first
IIF
is used to show blanks in other years.
- The last
IIF
is used for the total.
And some pictures of this measure's behavior:
If you want the same value on each level of 2014 and its children (but blanks for others), use
AGGREGATE(
{Exists(
Descendants(
[Create Date].[Create Date].[Year].&[2014],
[Create Date].[Create Date].[Month],
AFTER)
)
},
[Measures].[Count]
)
or SUM
. But I guess it will look like IgnoreUnrelatedDimensions=True
for this member and children, as you said before.
One more tip: if there is a filtering on another levels you can play with Descendants
levels and flag parameter (AFTER
, BEFORE
, SELF_AND_AFTER
etc.)
This article can help to understand this technique: http://www.sqllion.com/2011/08/mdx-descendants/
Hope this will help to solve the problem.
UPDATE
For the lowest level it's better to use Ascendants
like this:
CREATE MEMBER CURRENTCUBE.[Measures].[TestAgg2]
AS
IIF(
Intersect(
[Create Date].[Create Date].CurrentMember,
Exists(
Ascendants([Create Date].[Create Date].[Day].&[20140214])
)
).Count > 0,
(
[Create Date].[Create Date].[Day].&[20140214],
[Measures].[Count]
),
IIF(
[Create Date].[Create Date].CurrentMember is [Create Date].[Create Date].[All],
AGGREGATE(
{[Create Date].[Create Date].[Day].&[20140214]},
[Measures].[Count]
),
null
)
),
VISIBLE = 1;