matching for group (Expressions) in same column in Spotfire

a 夏天 提交于 2019-12-04 02:31:44

Ok, this one really tested my limits and I'm curious if it will scale. It works for your data, given where you have NULL. It took a few hours to figure out.

  1. Insert a calculated column RowId() and name it RowNum
  2. Insert a calculated column RankReal([status],"ties.method=first") and name it Rank
  3. Insert a calculated column If((first([status]) over (Previous([RowNum])) - First([status]) over ([RowNum]))=0,[Rank] - Max([RowNum]) OVER (Intersect([status],AllPrevious([RowNum])))) and name it GroupOfTypes
  4. Inert a calculated column If([type]>Min([type]) over (Intersect([GroupOfTypes],AllNext([RowNum]))),"T") and name it Marking. This is the row you really care about.

Results

EXPLANATION

RankReal([status],"ties.method=first")

This is done to essentially create a pseudo rownumber based on a segment of statuses. You'll see it ranks based on the status, sequentially. It's the first step in my method to group your data.

If((first([status]) over (Previous([RowNum])) - First([status]) over ([RowNum]))=0,[Rank] - Max([RowNum]) OVER (Intersect([status],AllPrevious([RowNum]))))

The first part of this, (first([status]) over (Previous([RowNum])) - First([status]) over ([RowNum]))=0 is evaluating if the previous row's [status] column is the same as the current row. If it is, it returns a boolean TRUE value. If it is the same as it's previous row, we know that it belongs in the same block / grouping, so we do some math to label this column with the same value for the entire block. That is [Rank] - Max([RowNum]) OVER (Intersect([status],AllPrevious([RowNum]))). Therefore, each row within our grouping will equate to the same value.

If([type]>Min([type]) over (Intersect([GroupOfTypes],AllNext([RowNum]))),"T")

Lastly we evaluate if the [type] is larger than the mnimal [type] over all the next rows, based on the rownumber. This limits the data we focus on to those where [type] = 1 without actually filtering the rows, while only looking forward in the dataset. If this is true we flag it with T.

@ZAWD - Another way of solving this.

Step 1: Created a RowID using the expression RowId()

Step 2: Created a calculated column 'Mark0' using the expression below. This step is to find current type is not 0 and its consecutive type is 0.

Note:This column runs in the background. Need not be included in the table. Also, 100 is some dummy value which is only used to ensure that the condition is satisfied

If((Sum([type]) over ([RowID])!=0) and (Sum([type]) over (Next([RowID]))=0),100)

Step 3: Created a calculated column 'Mark1' using the expression below. This step is to find current type is not 0 and its consecutive type is also not 0 and Mark0 is filled.

Note: This column runs in the background. Need not be included in the table

If((Sum([type]) over ([RowID])!=0) and (Sum([type]) over (Next([RowID])) Is Not Null) and (first([Mark0]) over (allNext([RowID]))=100),100)

Step 4: Finally, created 'final mark' column using the expression below which marks 100 in Mark0 and Mark1 columns as 'T'

If(([Mark0]=100) or ([Mark1]=100),"T",null)

Final Table:

I have tested this with your data as well as different scenarios like three consecutive 1s in 'type' column instead of two and seems to be working fine. Please test it and let me know if this is stable.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!