我的数据如下表所示,其中预期出货金额新增实际上是每个索赔计数的平均出货量,但我无法正确汇总(总计应为26.3
,而不是0
)。有谁知道如何做到这一点?
CliID | Claim Count | Expected Shipment Amount | CliId Count Expected Shipment Amount New
All | 5 | 61.8 | 2 | 0
159061| (null) | (null) | (null) | (null)
159063| (null) | (null) | (null) | (null)
166759| 2 | 34.2 | 1 | 17.1
166769| (null) | (null) | (null) | (null)
223983| 3 | 27.6 | 1 | 9.2
此预成员应计算每个CliID的平均值,如果没有预期出货金额,则返回null:
CREATE MEMBER CURRENTCUBE.[Measures].[Expected Shipment Amount Pre]
AS IIf(IsLeaf([Claim].[CliID].currentmember),
([Measures].[Expected Shipment Amount]/[Measures].[Claim Count]),0),
VISIBLE = 0;
然后这应该是可见的,以便所有内容都正确聚合:
CREATE MEMBER CURRENTCUBE.[Measures].[Expected Shipment Amount New]
AS SUM([Measures].[Expected Shipment Amount Pre]),
VISIBLE=1;
很明显,在汇总级别,它会查看Expected Shipment Amount Pre
并返回0
,因为汇总本身并不是叶子,但对于汇总我来说。我喜欢计算所有的孩子,然后加起来。我怎样才能做到这一点?
答案 0 :(得分:2)
在第二步中,您应该使用
CREATE MEMBER CURRENTCUBE.[Measures].[Expected Shipment Amount New]
AS SUM(EXISTING [Claim].[CliID].[CliID].Members, [Measures].[Expected Shipment Amount Pre]),
VISIBLE=1;
我。即对CliID
级别成员的总结。
修改强>
您可以尝试加快速度的方法是更多地依赖内置的Analysis Services聚合。为此,请根据事实表中的Expected Shipment Amount New
列创建物理度量 Expected Shipment Amount
,并将其聚合函数设置为“sum”。然后,在计算脚本中,只需添加
SCOPE([Claim].[CliID].[CliID].Members);
[Measures].[Expected Shipment Amount New] = [Measures].[Expected Shipment Amount] / [Measures].[Claim Count];
END SCOPE;
这将使用平均值计算覆盖叶级别上的“预期出货金额新值”的计算,但不会对All
属性层次结构的CliID
级别进行任何说明。因此,对于此级别,应该执行度量的指定聚合,即sum
。