简体   繁体   English

将MDX计算的度量转换为SSAS计算的范围

[英]Convert MDX calculated measure, to scope in SSAS calculations

I have got a measure, getting the last value of a currency exchange rate. 我有一个度量,可以获取货币汇率的最后一个值。 The fact having the exchange rates, is configured in the dimension usage with the time dimension, and is daily based. 具有汇率的事实在时间用法的维度用法中进行配置,并且是基于每日的。 So, using MDX, I am successfully getting my converted measure in my currencies, by using a calculated measure: 因此,使用MDX,我可以通过使用计算得出的指标来成功获得以货币为单位的换算指标:

with member [Measures].[Calculated Comp Money In] as 
SUM([Dim Time].[Date Key].CurrentMember,
        [Measures].[Comp Money In]/[Measures].[Last Currency Rate])

And then in the where clause, I would filter out what currency I am reporting figures on 然后在where子句中,我将过滤出我要报告的货币使用的货币

[Dim Currency].[Currency Key].&[200]

However, what I don't like is that I have a [Measures].[Comp Money In], and a [Measures].[Comp Money In Calculated].... Can I use the SCOPE function in MDX, so that [Measures.[Comp Money In] is configured with the calculation above ? 但是,我不喜欢的是我有一个[Measures]。[Comp Money In]和[Measures]。[Comp Money In Calculated] .... 我可以在MDX中使用SCOPE函数,以便[Measures。[Comp Money In]配置了以上计算 I would then add this calculation in the calculations section of SSAS. 然后,我将在SSAS的“计算”部分中添加此计算。

If you use the Enterprise edition of SSAS, you can use the measure expression property of your measure do currency conversion. 如果使用SSAS的企业版,则可以使用度量进行货币换算的度量表达属性。 This is not very well documented in the Analysis Services documentation, but works as follows: You use only one measure (ie either [Measures].[Calculated Comp Money In] or [Measures].[Comp Money In] , and in the "Measure expression" property of this measure, enter the expression that you have in your question above: 这在Analysis Services文档中记录得不是很好,但是其工作方式如下:您仅使用一种度量(即[Measures].[Calculated Comp Money In][Measures].[Comp Money In] ,以及在“该度量的“度量表达式”属性,请在上面的问题中输入您拥有的表达式:

[Measures].[Comp Money In] / [Measures].[Last Currency Rate]

Then the Analysis Services engine will take care of the rest for you. 然后,Analysis Services引擎将为您处理其余的工作。 Note that this expression may only contain the measure on which you define it, times or divided by one other measure (normally he exchange rate) and nothing else. 请注意,此表达式只能包含定义时所用的度量,时间或除以另一个度量(通常为汇率)而没有其他值。

If you do not have The Enterprise edition of Analysis Services, you can more or less copy your definition to a calculated member: 如果您没有Analysis Services的企业版,则可以或多或少地将定义复制到计算所得的成员中:

To be able to continue using the existing measure, possibly rename the measure [Measures].[Comp Money In] to [Measures].[_Comp Money In] (and make that measure invisible when you have checked that everything is fine). 为了能够继续使用现有度量,可以将度量[Measures].[Comp Money In]重命名为[Measures].[_Comp Money In] (并在您检查完一切正常后使该度量不可见)。 Then define a calculated member with the same name as the original measure: 然后定义一个与原始度量同名的计算成员:

create member CurrentCube.[Measures].[Comp Money In] as 
       SUM([Dim Time].[Date Key].CurrentMember,
           [Measures].[_Comp Money In]/[Measures].[Last Currency Rate])

Better still, use SCOPE to calculate the measure, and avoid the aggregation for single days: Assuming the only common dimension between the measure group containing [Measures].[Comp Money In] and the measure group containing [Measures].[Last Currency Rate] is [Dim Time] and this has the key attribute [Dim Time].[Date Key] , and your date hierarchy is named [Dim Time].[Date] , you could just use 更好的是,使用SCOPE来计算度量,并避免单日汇总:假设包含[Measures].[Comp Money In]的度量组和包含[Measures].[Last Currency Rate]的唯一共同维度[Measures].[Last Currency Rate][Dim Time]并且具有键属性[Dim Time].[Date Key] ,并且您的日期层次结构名为[Dim Time].[Date] ,您可以使用

CREATE MEMBER CurrentCube.[Measures].[Comp Money In] as NULL;
SCOPE([Dim Time].[Date Key].[Date Key].members);
    [Measures].[Comp Money In] =
        [Measures].[_Comp Money In] / [Measures].[Last Currency Rate];
END SCOPE;
SCOPE([Dim Time].[Date].Members);
    [Measures].[Comp Money In] =
        Sum(EXISTING [Dim Time].[Date Key].[Date Key].members);
END SCOPE;

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

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