【问题标题】:LAG/LEAD using Spotfire custom expressionLAG/LEAD 使用 Spotfire 自定义表达式
【发布时间】:2017-11-07 18:36:59
【问题描述】:

我的输入数据表是这样的

ID      AdmitDate
ABC001  1/1/2017
XYZ007  1/2/2017
XYZ002  1/3/2017
ABC001  1/4/2017
ABC001  1/7/2017
XYZ002  1/7/2017

我正在尝试检索每次新访问的先前录取日期。输出应该是这样的。

ID      AdmitDate   PreviousAdmitDate
ABC001  1/1/2017    
XYZ007  1/2/2017    
XYZ002  1/3/2017    
ABC001  1/4/2017    1/1/2017
ABC001  1/7/2017    1/4/2017
XYZ002  1/7/2017    1/3/2017

在 SQL 中,我会做类似...

LAG(AdmitDate, 1, Null) OVER (PARTITION BY ID ORDER BY AdmitDate) AS PreviousAdmitDate

我从this 帖子中尝试了以下解决方案,但没有奏效。

First([AdmitDate]) OVER (Intersect([ID], Previous([AdmitDate])))

Spotfire 的自定义表达方式是什么?

【问题讨论】:

    标签: spotfire


    【解决方案1】:

    @WeShall - 步骤如下:

    第 1 步:添加一个计算列,该列的 ID 计数递减。

    Count([ID]) over (intersect([ID],AllNext([AdmitDate])))
    

    第 2 步:现在,使用上一步中的计算列,添加一个显示相同 ID 上一个日期的计算列。

    Min([AdmitDate]) over (Intersect([ID],Next([decreasing_count])))
    

    注意:“decreasing_count”列可以在后台工作。不必在表格中显示。

    最终输出表:

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多