计算 Spotfire 中特定行的同一列的差异

ZAW*_*AWD 2 calculated-columns difference spotfire

我在 Spotfire 中使用计算列进行行差异计算时遇到问题。

我想知道是否可以创建一个计算列来计算当前行与具有不同属性的下一行之间的差异。示例表可能是这样的:

在此输入图像描述

结果可能是这样的:

在此输入图像描述

基本行是:

  1. 类型=1 时,计算其当前与其下一个最接近的类型=0 的行之间的差值,然后将结果添加到新的计算列中。
  2. 顺便说一句,价值总是增加:)
  3. 例如,对于第一个结果2,当前值为 20,下一行是与 0 最接近的类型,下一行的值为 22,则结果为 2
  4. 但对于下一个 type=1,当前值为 25,并且最接近的 type=0 在第六行,因此结果可能是 29-25=4

我尝试过的方法:

  1. 我添加了一个新的 RowID 列
  2. 然后尝试代码:

    if([type]=1),[value] - Sum([value]) OVER (PreviousPeriod([RowID])),null)
    
    Run Code Online (Sandbox Code Playgroud)

但它只是显示类型 1、无类型 1 和类型 0 之间的区别:(

任何帮助或建议将不胜感激:)

谢谢!

scs*_*mon 5

  1. 插入一列RowId()并为其命名RowNum
  2. 插入具有以下表达式的列:

([value] - first([value]) over (intersect(previous([type]),AllNext([RowNum])))) * -1

这是它的样子。我将该列命名为t1. 您也可以忽略该Val列:

结果

解释:

这里的技巧是将OVER子句中的值限制为当前行之后的值。此外,我们希望获得第一个、下一个符合我们标准的可用值。因此,我们采用第一个值 ,first([value])它具有先前的[type]。这始终为 0,因为 没有任何负值[type],因此这将我们正在使用的行限制为[type] = 1使用 的行previous([type])。现在,为了将其限制为仅当前行之后的行,我们使用AllNext([RowNum]). 该Intersect声明指出在满足这两个规则的情况下取值。所以看着RowNum = 4是这样评价的。

[value] = 25
Previous([type])= 0 since current type is 1
AllNext([RowNum]) = RowNum that is > our RowNum which is 4, so tow numbers 5 - 7
The First([Value]) that meets these criteria is in RowNum = 6, which is 29 since it has [Type] = 0 and it's RowNum is > 4
Note, Row 7 also meets this criteria but it isn't the First() one.
Now, do the math... 25-29 = -4, and since you said the values always increase, we just multiply by -1 to get it in the format you wanted
Run Code Online (Sandbox Code Playgroud)