ZAW*_*AWD 2 calculated-columns difference spotfire
我在 Spotfire 中使用计算列进行行差异计算时遇到问题。
我想知道是否可以创建一个计算列来计算当前行与具有不同属性的下一行之间的差异。示例表可能是这样的:
结果可能是这样的:
基本行是:
我尝试过的方法:
然后尝试代码:
if([type]=1),[value] - Sum([value]) OVER (PreviousPeriod([RowID])),null)
Run Code Online (Sandbox Code Playgroud)但它只是显示类型 1、无类型 1 和类型 0 之间的区别:(
任何帮助或建议将不胜感激:)
谢谢!
RowId()并为其命名RowNum([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)