0

Using MDX to return for each client, their latest status within a defined date range.

Sample Dataset:

Client | Status   | Date
A      | Pending  | 30-Jun-12
A      | Pending  | 01-Jul-12
A      | Active  | 02-Jul-12
A      | Active  | 03-Jul-12
B      | Pending  | 01-Jun-12
B      | Active  | 02-Jun-12
B      | Active  | 03-Jun-12
B      | Active  | 04-Jun-12

Additional Info: (No records for client A after 3-Jul-12 as they no longer receive a service) (No records for client B after 4-Jun-12 as they no longer receive a service)

REQUIRED OUTPUT: If Date dimension is filtered for all of June 2012 it should return

Client | Status   | Date
A      | Pending  | 30-Jun-12
B      | Active  | 04-Jun-12

Environment: SSAS 2005 | SS 2008 R2 | VS 2008

Hoping to use calculated member or named set but any help/guidance greatly appreciated...

4

1 回答 1

0

由于您缺少很多细节,我只是假设缺少的信息:

  • 不需要多选。
  • 您的客户端层次结构名为[Client].[Client]
  • 您的 Status 层次结构名为[Status].[Status],即它位于与维度不同的Client维度上。
  • 您的日期层次结构以[Date].[Date]日级别[Date].[Date].[Day]和月级别命名[Date].[Date].[Day]
  • 2012 年 6 月的成员密钥是201206.
  • 连接上述维度的度量组称为Sales
  • 您的多维数据集名为Cube

然后

WITH   Set [Days] as
           Descendants([Date].[Date].CurrentMember, [Date].[Date].[Day])
       Member [Measures].[Date] as 
              Exists([Days], {[Client].[Client].CurrentMember}, 'Sales')
                    .Item(Exists([Days], {[Client].[Client].CurrentMember}, 'Sales').Count - 1)
                    .Item(0)
                    .Name
SELECT { [Measures].[Date] }
       ON COLUMNS,
       NON EMPTY
       [Client].[Client].[Client].Members
       *
       [Status].[Status].[Status].Members
       ON ROWS
  FROM [Cube]
 WHERE [Date].[Date].[Month].&[201206]

应该提供你想要的。

[Days]集合包含过滤日期范围内的所有日期。然后,Date度量值计算如下: 将Exists限制为Days当前客户端的值,第Item一个从该集合中提取最后一个元组,第二个Item将其转换为成员,然后将该成员的名称作为Date度量返回。

编辑

要获得每个状态不是一行,而是最后一个状态(假设每天最多有一条记录),您也可以将状态转换为度量:

WITH   Set [Days] as
           Descendants([Date].[Date].CurrentMember, [Date].[Date].[Day])
       Member [Measures].[Date] as 
              Exists([Days], {[Client].[Client].CurrentMember}, 'Sales')
                    .Item(Exists([Days], {[Client].[Client].CurrentMember}, 'Sales').Count - 1)
                    .Item(0)
                    .Name
       Member [Measures].[Status] as 
              Exists([Status].[Status].[Status].Members,
                     { Exists([Days], {[Client].[Client].CurrentMember}, 'Sales')
                            .Item(Exists([Days], {[Client].[Client].CurrentMember}, 'Sales').Count - 1)
                     },
                     'Sales'
                    )
                    .Item(0)
                    .Item(0)
                    .Name
SELECT { [Measures].[Status], [Measures].[Date] }
       ON COLUMNS,
       NON EMPTY
       [Client].[Client].[Client].Members
       ON ROWS
  FROM [Cube]
 WHERE [Date].[Date].[Month].&[201206]

Exists度量的外部Status找到包含日期状态的一个元素集,然后通过Item(0)对成员的两次调用将其转换,我们可以从中获取名称。

于 2013-10-16T18:22:36.983 回答