[英]calculation the difference for same column for the specific rows in Spotfire
我在Spotfire中使用计算列对行的差异计算存在问题。
我想知道是否有可能创建一个计算列,该列将计算当前行与具有不同属性的下一行之间的差异。 样本表可能是这样的:
结果可能是这样的:
基本行是:
我尝试过的方法:
然后尝试代码:
if([type]=1),[value] - Sum([value]) OVER (PreviousPeriod([RowID])),null)
但它只是显示类型1,没有类型1和类型0之间的区别:(
任何帮助或建议,将不胜感激:)
谢谢!
RowId()
并将其命名为RowNum
([value] - first([value]) over (intersect(previous([type]),AllNext([RowNum])))) * -1
这就是它的样子。 我将列命名为t1
。 您也可以忽略Val
列:
说明:
这里的技巧是将OVER
子句中的值限制为当前行之后的值。 此外,我们希望获得符合我们标准的第一个,下一个可用值。 因此,我们采用第一个值first([value])
,它具有先前的[type]
。由于[type]
没有任何负值,所以它始终为0,因此这限制了我们要处理的行通过使用previous([type])
获得[type] = 1
的那些。 现在,要将其限制为仅在当前行之后的行,我们使用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
@ZAWD-解决此问题的另一种方法:
步骤1:使用表达式RowId()插入计算列'RowID'
步骤2:使用以下表达式插入计算列'test0'
sum([Value]) over (Intersect(next([RowID]),Previous([Type])))
步骤3:使用以下表达式插入计算列“ test”
[Value] - sum([test0]) over (Next([RowID]))
步骤4:使用以下表达式插入计算列“ myresult”
Abs(If((Sum([Type]) over ([RowID])=1) and (Sum([Type]) over (Next([RowID]))=1),[test],[Value] - [test0]))
注意:“ test0”和“ test”列在后台运行。 它们不必包含在主表中
决赛桌如下:
此外,此解决方案按值的顺序排列都可以正常工作。我已经在不同的场景下测试了此解决方案,并且看起来工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.