Summary
I'm new to MDX but have been asked to enhance currency conversion functionality in a cube. The problem itself seems simple.
For any given selected period, get the last date, and use that as the Reporting date for FX currency conversion.
For example, user selects periods Jan 2018 through to Oct 2018. The last date would be 31-Oct-2018.
The currency conversion is many to one reporting currency so we would take rates from the 31-Oct-2018.
Methods Tried
I have tried various methods to get the last date using:
- MAX (with and without existing)
- ClosingPeriod
- Separate FX Rate Measure Group and Date Dimension
These work fine if the user selects one period and the calculation is only for that period.
However the problem is that across multiple periods (think YTD or LTD calculations) then end rate is taken from each month.
For example, each line item here in the corresponding month would be converted using the rate at period value for that month (Jan 7.285) rather than using the Oct 2018 value of 7.027.
Period | Rate at Period | LastDate | LastDateExisting
Jan 2018 | 7.285 | 20191231 | 20180131
Feb 2018 | 7.273 | 20191231 | 20180228
Mar 2018 | 7.275 | 20191231 | 20180331
Apr 2018 | 7.201 | 20191231 | 20180430
May 2018 | 7.146 | 20191231 | 20180531
Jun 2018 | 7.118 | 20191231 | 20180630
Jul 2018 | 7.116 | 20191231 | 20180731
Sep 2018 | 7.102 | 20191231 | 20180930
Oct 2018 | 7.027 | 20191231 | 20181031
Example Code
Here is an example of the MAX method I have found in various MDX cookbooks to get the last Date. I am assuming that due to the CurrentMember I am getting results per period. I realise this is normal MDX behaviour but due to the requirement would need to break this.
The MAX example without existing is the closest as it returns the same date but I am not sure if this can be filtered for the actual closing period easily?
WITH
MEMBER Measures.[LastDate] AS
MAX( [Accounting Date].[Year – Quarter – Month – Date].[Date].MEMBERS,
IIF( [Measures].[Rate at Period] = 0,
NULL,
[Accounting Date].[Year – Quarter – Month – Date].CurrentMember.Member_Key
)
)
MEMBER Measures.[LastDateExisting] AS
MAX( EXISTING [Accounting Date].[Year – Quarter – Month – Date].[Date].MEMBERS,
IIF( [Measures].[Rate at Period] = 0,
NULL,
[Accounting Date].[Year – Quarter – Month – Date].CurrentMember.Member_Key
)
)
Expected Results
I would like to see the last date column as all ‘20181031’ as below.
Period | Rate at Period (overridden) | LastDate
Jan 2018 | 7.027 | 20181031
Feb 2018 | 7.027 | 20181031
Mar 2018 | 7.027 | 20181031
Apr 2018 | 7.027 | 20181031
May 2018 | 7.027 | 20181031
Jun 2018 | 7.027 | 20181031
Jul 2018 | 7.027 | 20181031
Sep 2018 | 7.027 | 20181031
Oct 2018 | 7.027 | 20181031
Any help appreciated and happy to provide more information should you need it.