Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSAS dealing with non linked data

I'm trying to compare forecast data with sales data in a cube. Sometimes we have a forecast with no actual sale, sometimes we have a sale with no forecast. How do just show 0% if one or the other does not exist? This is my current code... Green lines are ok because it is showing 0% where one of the amounts doesn't exist. I want it to do the same for the red circled ones.

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'  ; 

enter image description here

EDIT - if both measure values don't exist they would both be null and wouldn't display. So I wouldn't want the percentage to display either and I only want to do the calculation if one of the quantities is not 0. Forecast accuracy should not show 100% if f amount is 0 and there is a sale as shown in the last img... this is the last thing to correct...

enter image description here

like image 246
jhowe Avatar asked Jul 12 '16 10:07

jhowe


People also ask

Should SSAS be on a dedicated server?

If you have all of your SQL databases on the same box in may be wise to consider a separate server for SSAS. If SSAS is used heavily and you have large cubes then it would be best on a separate server. There are many factors to consider - volume and velocity of data, query types, concurrency, cost etc. Good luck.

How do I create a relationship in SSAS?

Click (and hold) on a column within a table, then drag the cursor to a related lookup column in a related lookup table, and then release. The relationship will be created in the correct order automatically.


2 Answers

I prefer the safety of 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' ; 

Slightly more complicated:

 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' ; 
like image 167
whytheq Avatar answered Oct 15 '22 08:10

whytheq


I think whytheq's answer did most of it. The only thing I think you needed was to check if both values are more than zero to return a score, and yes, it will work with any dimension that your SSAS model allow. Something like the following should give you what you need:

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' ; 
like image 2
BICube Avatar answered Oct 15 '22 07:10

BICube