【问题标题】:Exclude a member for MDX forecasting using linear regression使用线性回归为 MDX 预测排除成员
【发布时间】:2015-09-11 14:13:45
【问题描述】:

我想使用完整前几个月的数据来预测下个月的度量值。

例如在 9 月 11 日这一刻,我必须根据 1 月至 8 月的值来预测 9 月的值(因为 9 月尚未结束)。

我正在使用 MDX 函数 LinRegPoint,其层次结构详述如下

  • 昏暗时间
    • 层次结构时间
      • 年份
      • 季度

这是我一直在尝试但没有成功的查询:

WITH 
  MEMBER [Measures].[Trend] AS 
    LinRegPoint
    (
      Rank
      (
        [Time].[Hierarchy Time].CurrentMember
       ,[Time].[Hierarchy Time].CurrentMember.Level.MEMBERS
      )
     ,Descendants
      (
        [Time].[Hierarchy Time].[2015]
       ,[Time].[Hierarchy Time].CurrentMember.Level
      )
     ,[Measures].[Quality]
     ,Rank
      (
        [Time].[Hierarchy Time]
       ,[Time].[Hierarchy Time].Level.MEMBERS
      )
    ) 
SELECT 
  {
    [Measures].[Quality]
   ,[Measures].[Trend]
  } ON COLUMNS
 ,Descendants
  (
    [Time].[Hierarchy Time].[2015]
   ,[Time].[Hierarchy Time].[Month]
  ) ON ROWS
FROM [Cube];

上述查询返回包括9月份在内的所有月份预测值到今天日期,但是它预测9月份值时取1月到9月份当前日期的实际值。在这种情况下,我需要 LinRegPoint 函数只需要前一个完整的月份,即 1 月到 8 月。

请注意,查询返回 9 个月(9 月)的预测值,但它使用实际值来计算它。这会导致如下图所示的错误线。

此图显示了上一整月 (1-8) 的绘制线:

注意正斜率线。

这张图片显示了绘制所有月份 (1-9) 的线

注意负斜率线。

问题: 如何从实际值中排除不完整的当前月份,但允许计算预测值。

编辑: 该集合应更改为以实际值排除最后一个月的成员,但为其计算预测值。

感谢您考虑我的问题。

解决方案:

WITH MEMBER [Measures].[Trend] AS 
  LinRegPoint
  (
    Rank(
        [Time].[Hierarchy Time].CurrentMember
       ,[Time].[Hierarchy Time].CurrentMember.Level.MEMBERS
        )
    ,Descendants
    (
        [Time].[Hierarchy Time].[2015]
       ,[Time].[Hierarchy Time].CurrentMember.Level
    )
    ,[Measures].[QltyNoCurrentVal]
    ,Rank(
        [Time].[Hierarchy Time]
       ,[Time].[Hierarchy Time].Level.MEMBERS)
    ),FORMAT_STRING='Standard' //Formating
MEMBER [Measures].[QltyNoCurrentVal] AS 
    IIF(
        [Time].[Hierarchy Time].CurrentMember is [Time].[Hierarchy Time].[2015].[3].[9]
       , NULL
       , [Measures].[Quality]
    ),FORMAT_STRING='Standard' //Formating
select {
    [Measures].[QltyNoCurrentVal]
   ,[Measures].[Trend]} ON COLUMNS
   ,Descendants(
        [Time].[Hierarchy Time].[2015]
       ,[Time].[Hierarchy Time].[Month]
   ) ON ROWS
FROM [Cube]

【问题讨论】:

    标签: sql-server-2012 ssas mdx linear-regression forecasting


    【解决方案1】:

    有点困惑你的表达式中的哪些集合需要改变。

    我创建了一个集合 [MthsExclSept],您应该可以在脚本的其余部分中使用它 - 我刚刚在两个地方使用了它:

    WITH 
      SET [MthsExclSept] AS 
        SubSet
        (
          Descendants
          (
            [Time].[Hierarchy Time].[2015]
           ,[Time].[Hierarchy Time].[Month]  //<<better to specify the month level
          )
         ,0
         ,
            Descendants
            (
              [Time].[Hierarchy Time].[2015]
             ,[Time].[Hierarchy Time].[Month]  //<<better to specify the month level
            ).Count
          - 1
        ) 
      MEMBER [Measures].[Trend] AS 
        LinRegPoint
        (
          Rank
          (
            [Time].[Hierarchy Time].CurrentMember
           ,[MthsExclSept] //<<also added here?
          )
         ,[MthsExclSept]
         ,[Measures].[Quality]
         ,Rank
          (
            [Time].[Hierarchy Time]
           ,[MthsExclSept] //<<also added here?
          )
        ) 
      MEMBER [Measures].[QualityNEW] AS 
        IIF(
            [Time].[Hierarchy Time].CurrentMember is [Time].[Hierarchy Time].[September]
           , NULL
           , [Measures].[Quality]
        )
    SELECT 
      {
        [Measures].[QualityNEW]
       ,[Measures].[Trend]
      } ON COLUMNS
     ,[MthsExclSept] ON ROWS
    FROM [Cube];
    

    集合[MthsExclSept] 刚刚剪掉了上个月。这是来自 AdvWrks 的证明,它从一年中删除了 12 月:

    WITH 
      SET [MthsExclSept] AS 
        SubSet
        (
          Descendants
          (
            [Date].[Calendar].[Calendar Year].&[2009]
           ,[Date].[Calendar].[Month]
          )
         ,0
         ,
            Descendants
            (
              [Date].[Calendar].[Calendar Year].&[2009]
             ,[Date].[Calendar].[Month]
            ).Count
          - 1
        ) 
    SELECT 
      {} ON 0
     ,[MthsExclSept] ON 1
    FROM [Adventure Works];
    

    它返回以下内容:

    【讨论】:

    • 我试过你的脚本,但它什么也没返回。我的意思是它不会返回 null 或错误,但不会返回您创建的行 [MthsExclSept] 子集。谢谢。
    • 我不是统计学家——你不是也需要在 rank 函数中使用新的集合吗? (我已经编辑了答案)
    • 现在使用您编辑的脚本,我得到了 1-8 个月的实际值和预测值,但不是 9 个月的预测值。我之前已经使用除外函数完成了该操作。我对此感到困惑,我不确定我必须在 LinRegPoint 函数中排除上个月(新集)的位置,以便不使用实际值,而是计算它的预测值。谢谢
    • 也许不要在你的脚本中使用[MthsExclSept] ON ROWS?将该部分更改回您的状态Descendants ( [Time].[Hierarchy Time].[2015] ,[Time].[Hierarchy Time].[Month] ) ON ROWS
    • 它返回 9 个月的实际值和预测值,但是预测值受该月实际值的影响,导致负斜率线,如我的问题最初所示。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-10
    • 2016-08-26
    相关资源
    最近更新 更多