每个事务的 MDX 开始和结束时间

MDX Start and End Time per transaction

我希望你能帮助我,我已经尝试了很多方法来尝试解决这个问题,但没有成功。我正在尝试获取玩家帐号、日期以及开始和结束日期时间,并可能计算开始时间和结束时间之间的播放持续时间。

我希望输出看起来像这样。

PlayerAccount | GamingDate | StartTime | EndTime | PlayDuration | ActualWin

我似乎总是 return 一整天的开始和结束时间,而不是每个帐户。

 WITH 
  SET [MySet] AS 
      [Customer].[Player Account Number].Children*
      Head
      (
        NonEmpty
        (
          [Start Time].[Hour].Children
         ,[Measures].[Actual Win]
        )
       ,1
      )*
      Tail
      (
        NonEmpty
        (
          [End Time].[Hour].Children
         ,[Measures].[Actual Win]
        )
       ,1
      ) 
SELECT 
  {[Measures].[Actual Win]} ON 0
 ,{[MySet]} ON 1
FROM 
(
  SELECT 
      [Customer].[Player Account Number].&[1040002184]
    : 
      [Customer].[Player Account Number].&[1040002198] ON 0
  FROM Ratings
)
WHERE 
  {[Gaming Date].[Full Date].&[20150101]};

您有一个静态集合(总是 return 相同的成员)。使用 EXISTING 关键字计算当前上下文中的开始和结束时间。

with member [Measures].[StartDate] as

    EXISTING    
    HEAD(
            nonempty(
                    [Start Time].[Hour].Children,[Measures].[Actual Win]
                    ) ,1
        ).ITEM(0).ITEM(0).MEMBERVALUE



member [Measures].[EndDate] as
    EXISTING
    TAIL(
            nonempty(
                    [End Time].[Hour].children,[Measures].[Actual Win]
                    ) ,1            
        ).ITEM(0).ITEM(0).MEMBERVALUE       


select 
    {
    [Measures].[Actual Win], 
    [Measures].[StartDate], 
    [Measures].[EndDate]
    } on 0,

    [Customer].[Player Account Number].children on 1

from
(
    select  (
            [Customer].[Player Account Number].&[1040002184]:
            [Customer].[Player Account Number].&[1040002198]
            )  on 0 
    from Ratings
)

where {[Gaming Date].[Full Date].&[20150101]}

重新安排了 [Customer].[Player Account Number] 以便在每个玩家帐户的上下文中评估日期。希望一切顺利!

编辑。

此方法的简化 AdWrks 版本如下:仍然不太有效:

WITH 
  SET [aSet] AS 
    (EXISTING 
      Head
      (
        NonEmpty
        (
          [Date].[Date].[Date].MEMBERS
         ,[Measures].[Internet Sales Amount]
        )
      )) 
SELECT 
  {[Measures].[Internet Sales Amount]} ON 0
 ,NON EMPTY 
    {[Promotion].[Promotion].MEMBERS * [aSet]} ON 1
FROM [Adventure Works];

通常第一个日期和最后一个日期是度量值。如果您只想要这两个玩家的结果,请使用 WHERE 子句而不是子 select:

WITH 
  MEMBER [Measures].[fDate] AS 
    Head
    (
      NonEmpty
      (
        [Start Time].[Hour].MEMBERS
       ,[Measures].[Actual Win]
      )
    ).Item(0).Item(0).Member_Caption 
  MEMBER [Measures].[lDate] AS 
    Tail
    (
      NonEmpty
      (
        [End Time].[Hour].MEMBERS
       ,[Measures].[Actual Win]
      )
    ).Item(0).Item(0).Member_Caption 
SELECT 
  {
    [Measures].[fDate]
   ,[Measures].[lDate]
   ,[Measures].[Actual Win]
  } ON 0
 ,{[Customer].[Player Account Number].Children} ON 1
FROM Ratings
WHERE 
  ([Gaming Date].[Full Date].&[20150101],
   { [Customer].[Player Account Number].&[1040002184]
    ,[Customer].[Player Account Number].&[1040002198]});

这是一个有效的 AdvWrks 脚本,它可以完成您想要实现的事情:

WITH 
  MEMBER [Measures].[firstDate] AS 
    Head
    (
      NonEmpty
      (
        [Date].[Date].[Date].MEMBERS
       ,[Measures].[Internet Sales Amount]
      )
    ).Item(0).Item(0).Member_Caption 
  MEMBER [Measures].[lastDate] AS 
    Tail
    (
      NonEmpty
      (
        [Date].[Date].[Date].MEMBERS
       ,[Measures].[Internet Sales Amount]
      )
    ).Item(0).Item(0).Member_Caption 
SELECT 
  {
    [Measures].[Internet Sales Amount]
   ,[Measures].[firstDate]
   ,[Measures].[lastDate]
  } ON 0
 ,NON EMPTY {[Promotion].[Promotion].MEMBERS} ON 1
FROM [Adventure Works];

如果您宁愿撤回成员而不是使用 Measures,我认为 GENERATE 函数将像 AdvWrks 示例一样工作:

WITH 
  SET [aSet] AS 
    Generate
    (
      [Promotion].[Promotion].MEMBERS
     ,
        [Promotion].[Promotion].CurrentMember
      * 
        Head
        (
          NonEmpty
          (
            [Date].[Date].[Date].MEMBERS
           ,[Measures].[Internet Sales Amount]
          )
        )
    ) 
SELECT 
  {[Measures].[Internet Sales Amount]} ON 0
 ,NON EMPTY 
    {[aSet]} ON 1
FROM [Adventure Works];

感谢一百万个 whytheq .Item(0).Item(0).Member_Caption 让一切变得不同,结果似乎现在就出来了。最终的解决方案现在看起来像这样..

with set [MySet]
as
[Casino Hierarchy].[Casino Key].children *
[Gaming Date].[Date].currentmember * 
[Customer].[Player Account Number].children *
[Start Time].[Hour].children

member [measures].[Mindate]
as
HEAD(nonempty([End Time].[Hour].children,[Measures].[Actual Win]),1).Item(0).Item(0).Member_Caption 

member [measures].[Maxdate]
as
TAIL(nonempty([Start Time].[Hour].children,[Measures].[Actual Win]),1).Item(0).Item(0).Member_Caption 

    select non empty
    {
    [Measures].[Actual Win],[measures].[Mindate],[measures].[Maxdate]
    } on 0, non empty
    { 
    [Customer].[Player Account Number].children
    } on 1
    from
    (
    select  ([Customer].[Player Account Number].&[1040002184]:[Customer].[Player Account Number].&[1040002198])  on 0 from Ratings
    )
    where 
    {
    [Gaming Date].[Full Date].&[20150101]
    }