Spotfire date difference using over function

前端 未结 2 691
孤独总比滥情好
孤独总比滥情好 2021-01-25 09:44

I have the following data set:

Item  ||  Date       || Client ID || Date difference
A     ||  12/12/2014 || 102       || 
A     ||  13/12/2014 || 102       || 1
         


        
2条回答
  •  渐次进展
    2021-01-25 10:43

    I used the following solution to deal with groups that had more than 2 rows/dates.

    First create a calculated column to provide a rank order by date within each group:

    RankDatePerUnit:

      Rank([EventDate],[Group_Name])
    

    Then another calculated column to do the date diff using an over expression to reference the previous date within the group.

    TimeSinceLastEvent:

    DateDiff("day",
       First([EventDate]) OVER (Intersect([Group_Name], Previous([RankDatePerUnit]))),
       [EventDate])
    

    Note: Duplicate date could be handled differently by using denserank. The above approach will not calculate a zero date diff between two rows from the same group with a duplicate time. They'll both calculate their delta from an earlier date within the same group if one exists.

提交回复
热议问题