I’m having trouble understanding if Spotfire allows for conditional computations between arbitrary rows containing numerical data repeated over data groups. I could not find anything to cue me onto a right solution.
Context (simplified): I have data from a sensor reporting state of a process and this data is grouped into bursts/groups representing a measurement taking several minutes each. Within each burst the sensor is measuring a signal and if a predefined feature (signal shape) was detected the sensor outputs some calculated value, V quantifying this feature and also reports a RunTime at which this happened.
So in essence I have three columns: Burst number, a set of RTs within this burst and Values associated with these RTs. I need to add a calculated column to do a ratio of Values for rows where RT is equal to a specific number, let’s say 1.89 and 2.76.
The high level logic would be:
If a Value exists at 1.89 Run Time and a Value exists at 2.76 Run Time then compute the ratio of these values. Repeat for every Burst. I understand I can repeat the computation over groups using OVER operator but I’m struggling with logic within each group... Any tips would be appreciated. Many thanks!
The first thing you need to do here is apply an order to your dataset. I assume the sample data is complete and encompasses the cases in your real data, thus, we create a calculated column:
RowID() as [ROWID]
Once this is done, we can create a calculated column which will compute your ratio over it's respective groups. Just a note, your B4
example is incorrect compared to the other groups. That is, you have your numerator and denominator reversed.
If(([RT]=1.89) or ([RT]=2.76),[Value] / Max([Value]) OVER (Intersect([Burst],Previous([ROWID]))))
Breaking this down...
If(([RT]=1.89) or ([RT]=2.76),
limits the rows to those where the RT = 1.89 or 2.76
. TRUE
[Value] / Max([Value]) OVER (Intersect([Burst],Previous([ROWID]))))
This takes the value for the row and divides it by the Max([Value])
over the grouping of [Burst]
and AllPrevious([ROWID])
. This is noted by the Intersect()
function. So, the denominator will always be the previous value for the grouping. Note that Max()
was a simple aggregate used, but any should do for this case since we are only expecting a single value. All Over()
functions require and aggregate to limit the result set to a single row.RESULTS