我正在尝试将预测数据与多维数据集中的销售数据进行比较。有时我们预测没有实际销售,有时我们有一个没有预测的销售。如果一个或另一个不存在,如何显示0%?这是我当前的代码...绿线是可以的,因为它显示0%,其中一个金额不存在。我希望它对红色圆圈的那些做同样的事情。
CREATE MEMBER CURRENTCUBE.[Measures].[Forecast Accuracy Amount %]
AS IIF([Measures].[Sales Line Amount TCUSD SF] <> 0 OR [Measures].[F Amount] <> 0, 1-ABS(DIVIDE(([Measures].[F Amount] - [Measures].[Sales Line Amount TCUSD SF]) , [Measures].[F Amount])), NULL),
FORMAT_STRING = "Percent",
VISIBLE = 1 , ASSOCIATED_MEASURE_GROUP = 'Sales Forecast' ;
编辑 - 如果两个测量值都不存在,则它们都将为空并且不会显示。所以我不希望百分比显示任何一个,如果其中一个数量不是0,我只想进行计算。如果f金额为0并且有最后一个显示的销售,预测准确度不应显示100% img ...这是要纠正的最后一件事......
答案 0 :(得分:3)
我更喜欢ISEMPTY
:
CREATE MEMBER CURRENTCUBE.[Measures].[Forecast Accuracy Amount %]
AS
IIF(
NOT ISEMPTY([Measures].[Sales Line Amount TCUSD SF])
OR
NOT ISEMPTY([Measures].[F Amount])
, 1-ABS(DIVIDE(
[Measures].[F Amount] - [Measures].[Sales Line Amount TCUSD SF]
,[Measures].[F Amount]
)
)
,NULL
),
FORMAT_STRING = "Percent",
VISIBLE = 1 , ASSOCIATED_MEASURE_GROUP = 'Sales Forecast' ;
稍微复杂一点:
CREATE MEMBER CURRENTCUBE.[Measures].[Forecast Accuracy Amount %]
AS
IIF(
ISEMPTY([Measures].[Sales Line Amount TCUSD SF])
AND
ISEMPTY([Measures].[F Amount])
, NULL //<<if both are empty
, IIF(
NOT ISEMPTY([Measures].[Sales Line Amount TCUSD SF])
OR
NOT ISEMPTY([Measures].[F Amount])
,1-ABS(
DIVIDE(
[Measures].[F Amount] - [Measures].[Sales Line Amount TCUSD SF]
,[Measures].[F Amount]
)
)
,0
)
),
FORMAT_STRING = "Percent",
VISIBLE = 1 , ASSOCIATED_MEASURE_GROUP = 'Sales Forecast' ;
答案 1 :(得分:2)
我认为为什么thethe的答案完成了大部分工作。我认为你唯一需要的是检查两个值是否大于零以返回分数,是的,它将适用于您的SSAS模型允许的任何维度。以下内容应该可以满足您的需求:
CREATE MEMBER CURRENTCUBE.[Measures].[Forecast Accuracy Amount %]
AS
IIF(
ISEMPTY([Measures].[Sales Line Amount TCUSD SF])
AND
ISEMPTY([Measures].[F Amount])
, NULL //<<if both are empty
, IIF(
//Getting here means, at minimum, one of the measures is not empty
// Calculate the score only if both values are non equal to zero otherwise default to zero
[Measures].[F Amount] <> 0 AND
[Measures].[Sales Line Amount TCUSD SF] <>0
,1-ABS(
DIVIDE(
[Measures].[F Amount] - [Measures].[Sales Line Amount TCUSD SF]
,[Measures].[F Amount]
)
)
,0
)
),
FORMAT_STRING = "Percent",
VISIBLE = 1 , ASSOCIATED_MEASURE_GROUP = 'Sales Forecast' ;