0
votes

I'm trying to convert the following SQL query into a calculated member in my SSAS cube.

SELECT ActionKey, AVG(1.0 * Days) AS AverageDays
FROM( SELECT ActionKey, UserKey, COUNT(DISTINCT DateKey) AS Days
        FROM [TEST].[dbo].[FactActivity]
        GROUP BY ActionKey, UserKey) a
        GROUP BY ActionKey

How do I do this in MDX? I tried the following but it's giving me wrong result

IIF([Measures].[Dim User Count] = 0, 0 , [Measures].[Dim Date Count]/[Measures].[Dim User Count])

In my cube, I have two derived measures . "Dim Date Count" which is count of rows in DimDate table and "Dim User Count" which is count of row of DimUser table. Both have many-many relationship with other dimensions of the cube, so i can calculate the distinct days and users easily.

2
does it work in any context? what do the results for your two measures [Measures].[Dim Date Count] and [Measures].[Dim User Count] look like?whytheq

2 Answers

1
votes

This worked

AVG([Users].[User Key].[User Key], [Measures].[DATE COUNT])

0
votes

(not a solution but maybe helps)

Are the two measures that you've created giving the results you expect? If you run the equivalent of the following against [YourCube] is it just the new measure [Measures].[AverageDays] that is wrong?

SELECT 
  NON EMPTY 
    {
      [Measures].[AverageDays]
     ,[Measures].[Dim Date Count]
     ,[Measures].[Dim User Count]
    } ON COLUMNS
 ,NON EMPTY 
    {
        [Action].[Action].MEMBERS
      * 
        [Date].[Calendar].[Month].ALLMEMBERS
    } ON ROWS
FROM  [YourCube];