MDX按月计算成员

时间:2017-05-18 20:46:47

标签: ssms mdx olap-cube ssms-2014

我正在SSMS 2014中进行查询,我需要按月[度量]。[百分比独特应用用户],这样我就可以动态计算月份增加百分比。我最好先从上个月与前一个月的比较开始,最终每个月都会以报告形式运行(因此需要动态)。

无论是否有我的DATE成员,[CurrentMonthUniqueUsers]和[LastMonthUniqueUsers]的计数保持不变(在示例中显示)。另外,如果没有我的WHERE语句,我只会获得非MEMBER行的结果。

layoutHistoryStack

下面的图片是我得到的结果。登录计数和唯一登录计数是有效的,并且不会按任何日期进行过滤。

Data Screenshot

我是MDX的新手,所以非常感谢任何帮助!

编辑(2017年5月22日):以下是与mytheq提供的答案有关的查询。请注意,它不是动态的,因为我必须在列上指定日期(201705)。

WITH
MEMBER [LastMonthUniqueUsers] as SUM({[Date].[Calendar].CurrentMember.Lag(2)},[Measures].[App Unique Users Loggedin])
MEMBER [CurrentMonthUniqueUsers] as SUM({[Date].[Calendar].CurrentMember.Lag(1)},[Measures].[App Unique Users Loggedin])
//
MEMBER [Measures].[Percent Unique App Users] AS ([CurrentMonthUniqueUsers]) / ([LastMonthUniqueUsers]), FORMAT_STRING = "Percent"
//
MEMBER [CurrentDate] As Now()
//

SELECT
    non empty[Project].[Client Name].children ON 0,
    non empty{[Measures].[Percent Unique App Users],
        [CurrentMonthUniqueUsers],
        [LastMonthUniqueUsers], 
        [Measures].[App Logins],
        [Measures].[App Unique Users Loggedin]} ON 1
FROM
    [OpsViewWarehouse]
WHERE
    [Date].[Year].[2017]

1 个答案:

答案 0 :(得分:1)

在您的查询中,您的CURRENTMEMBER是WHERE子句中的内容 - 即2017年 - 所以这不会返回一个月 - 它可能会返回成员[Date].[Calendar].[All]

[Date].[Calendar].CurrentMember

尝试在SELECT或WHERE子句中添加月份:

//
WITH 
  MEMBER [LastMonthUniqueUsers] AS 
    Sum
    (
      {[Date].[Calendar].CurrentMember.Lag(2)}
     ,[Measures].[App Unique Users Loggedin]
    ) 
  MEMBER [CurrentMonthUniqueUsers] AS 
    Sum
    (
      {[Date].[Calendar].CurrentMember.Lag(1)}
     ,[Measures].[App Unique Users Loggedin]
    ) 
  //
  MEMBER [Measures].[Percent Unique App Users] AS 
    [CurrentMonthUniqueUsers] / [LastMonthUniqueUsers] 
   ,FORMAT_STRING = "Percent" 
  //
  MEMBER [CurrentDate] AS 
    Now() 
SELECT 
  NON EMPTY 
      [Project].[Client Name].Children ON 0
 ,NON EMPTY 
    {[Date].[Calendar].[Month].&[Jan 2017]}  //<<<<<<change to a month member in your cube
  * {
      [Measures].[Percent Unique App Users]
     ,[CurrentMonthUniqueUsers]
     ,[LastMonthUniqueUsers]
     ,[Measures].[App Logins]
     ,[Measures].[App Unique Users Loggedin]
    } ON 1
FROM [OpsViewWarehouse];

以上也可能是几个月:

//
WITH 
  MEMBER [LastMonthUniqueUsers] AS 
    Sum
    (
      {[Date].[Calendar].CurrentMember.Lag(2)}
     ,[Measures].[App Unique Users Loggedin]
    ) 
  MEMBER [CurrentMonthUniqueUsers] AS 
    Sum
    (
      {[Date].[Calendar].CurrentMember.Lag(1)}
     ,[Measures].[App Unique Users Loggedin]
    ) 
  //
  MEMBER [Measures].[Percent Unique App Users] AS 
    [CurrentMonthUniqueUsers] / [LastMonthUniqueUsers] 
   ,FORMAT_STRING = "Percent" 
  //
  MEMBER [CurrentDate] AS 
    Now() 
SELECT 
  NON EMPTY 
    {
      [Measures].[Percent Unique App Users]
     ,[CurrentMonthUniqueUsers]
     ,[LastMonthUniqueUsers]
     ,[Measures].[App Logins]
     ,[Measures].[App Unique Users Loggedin]
    } ON 0
 ,NON EMPTY 
     {Date].[Calendar].[Month].MEMBERS  //<<<<<<change to the month hierarchy in your cube
   *  [Project].[Client Name].Children ON 1
FROM [OpsViewWarehouse];