I am new to MDX, So I would appreciate any pointers to resolve this issue.
I have a ProjectHiearchy like this:
Fund -> Project -> Event. At the event level, there is a cashflow amount. I need to calculate IRR. So I need to take all the cashflows that pertain to the projects/funds selected in the filters.
Here is the calculated measure that I have written (which calculates IRR using Excel-MDX). Here, I am using Descendants function to find all the members at the Event level for the current Member. So, if I am at the Project level, this will return all the events for the project. If I am at Fund level (which includes 1 or more projects), it will return all the events for all the projects. So far so good - it is working and producing what I wanted.
MEMBER [Measures].[IRR] AS
Excel ! IRR ( SetToArray
(
Descendants
( [Data].[ProjectHierarchy].CurrentMember,
[Data].[ProjectHierarchy].[Event] ),
CoalesceEmpty
( [Measures].[Sum of Cashflow], 0 )
) )
But the problem starts when I apply a filter on projects. For example, in my sample data set, I have Project P1 and P2 under Fund1 and projects P3&P4 under Fund2. I selected Projects P1-P3 in the Pivot Table. Logically, this means that the IRR for Fund2 should be calculated only using the Events of P3. But this filter is not getting applied. The value I get for IRR for Fund2 is exactly the same as if I made no filter.
I added a simple [Sum of Cashflows] measure also in the query, but that is taking the filters correctly. What I am doing wrong? How to make this IRR measure take the filter applied at the project level?
Here is the full query for your reference.
WITH MEMBER [Measures].[IRR] AS
Excel ! IRR ( SetToArray
(
Descendants
( [Data].[ProjectHierarchy].CurrentMember, [Data].[ProjectHierarchy].[Event] ),
CoalesceEmpty
( [Measures].[Sum of Cashflow], 0 )
) )
SELECT
{ [Measures].[IRR], [Measures].[Sum of Cashflow 3] } ON COLUMNS,
NON EMPTY Hierarchize
(
DrilldownMember
(
{
{
DrilldownLevel
(
{ [Data].[ProjectHierarchy].[All] },
,
,
INCLUDE_CALC_MEMBERS
)
}
},
{ [Data].[ProjectHierarchy].[Fund].&[Fund 1], [Data].[ProjectHierarchy].[Fund].&[Fund 2] },
,
,
INCLUDE_CALC_MEMBERS
)
) Dimension Properties UNIQUE_NAME,
PARENT_UNIQUE_NAME ON ROWS
FROM
(
SELECT (
{ [Data].[Project].&[P3], [Data].[Project].&[P2], [Data].[Project].&[P1] } ) ON COLUMNS
FROM [Model]
)
WHERE ( [Data].[Fund].[All] )