Luke George 2 Posted February 13, 2019 Share Posted February 13, 2019 I need to create a calculated column that looks at another data column containing groups of 0's and 1's and gives every group of 0 a successive integer. It's a bit hard to explain, but the example table below should make it clear. Existing Column Calculated Column 1 1 0 1 0 1 0 1 0 1 1 1 1 0 2 0 2 0 2 0 2 0 2 1 0 3 1 0 4 0 4 0 4 Is this kind of operation possible in spotfire if so, how Thanks Link to comment Share on other sites More sharing options...
Gaia Paolini Posted February 13, 2019 Share Posted February 13, 2019 Hi. Try this, at the expense of two intermediate calculated columns: rowID: RowId() This is to establish a unique sequence of rows. temp1: If(([existingColumn]=0) and (([rowID]=1) or (([existingColumn] - Min([existingColumn]) over (previous([rowID])))!=[existingColumn])),1,NULL) This will be 1 if: existingColumn is zero and: either it is the first row, or it changed from 1 to 0 from the previous row calculatedColumn: If([existingColumn]=0,Integer(Rank([existingColumn]) - 1 + Sum([temp1]) over (allprevious([rowID]))),NULL) This adds to the rank the cumulative sum of temp1 so far. Gaia Link to comment Share on other sites More sharing options...
Luke George 2 Posted February 14, 2019 Author Share Posted February 14, 2019 Thanks Gaia, that works perfectly! Link to comment Share on other sites More sharing options...
Luke George 2 Posted February 15, 2019 Author Share Posted February 15, 2019 Hi again Gaia, I had another related question I thought you may be able to help me with. Suppose I wanted to create another culculated column that further subdivides the initial calculated column from the above example. This new calculated column would simply subdivide in groups of a set integer, say 3, as in the below example. Is there a way to do this Initial Grouping New Calculated Column 0 1 1 1 1 1 1 1 2 0 0 2 3 2 3 0 0 3 4 3 4 3 4 3 5 3 5 3 5 3 6 0 4 7 Thanks so much! Link to comment Share on other sites More sharing options...
Gaia Paolini Posted February 15, 2019 Share Posted February 15, 2019 I think that is probably would be best done in TERR. Can you post as a new question Thanks. Gaia Link to comment Share on other sites More sharing options...
Luke George 2 Posted February 17, 2019 Author Share Posted February 17, 2019 Sure thing. Here is the new question: https://community.spotfire.com/questions/creating-group-subdivisions-using-calculated-columns Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now