每笔交易的MDX开始和结束时间

时间:2015-03-13 07:57:37

标签: ssas mdx cubes

我希望你可以帮助我尝试了很多方法来尝试做到这一点没有运气。我试图将玩家账号输出日期,开始和结束日期时间,并计算开始和结束时间之间的播放时间。

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

  

PlayerAccount | GamingDate | StartTime |结束时间| PlayDuration | ActualWin

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

 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]};

3 个答案:

答案 0 :(得分:2)

通常,第一个日期和最后一个日期将是度量。如果你只想要那两个玩家的结果,那么使用WHERE子句而不是子选择:

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

答案 1 :(得分:2)

感谢一百万个为什么看起来像是.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]
    }

答案 2 :(得分:0)

您正在使用静态集(始终返回相同的成员)。使用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];