SSAS处理非链接数据

SSAS dealing with non linked data

我正在尝试将预测数据与多维数据集中的销售数据进行比较。有时我们有没有实际销售的预测,有时我们有没有预测的销售。如果一个或另一个不存在,如何只显示 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...这是最后要更正的事情...

我更喜欢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' ; 

我认为 whytheq 的回答做了大部分。我认为您唯一需要做的就是检查两个值是否都大于零到 return 分数,是的,它适用于您的 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' ;