Clarivando Belizario Junior Posted September 16, 2019 Share Posted September 16, 2019 TABLE 1: Column_1 Column_2 A c B b A a D a A b B a A d C h C f D g I need to get a result like TABLE 2. TABLE 2: Column_1 Column_2 Previous(Column_2) A a - A b a A c b A d c B a d B b a C f b C h f D a h D g a I really need the column "Previous (Column_2)". I need to know what the previous value is for each row (Column_2) in table 2 because I need to compare both of them. Link to comment Share on other sites More sharing options...
Khushboo Rabadia Posted September 30, 2019 Share Posted September 30, 2019 You can get previous of column2 in the same table using calculated columns instead of creating sorted table2. 2. Data > Add calculated column... Column name: Rank Expression: DenseRank(RowId(),[Column_1]) 3. Data > Add calculated column... Column name: PrevCol2 Expression: First([Column_2]) OVER (Intersect(Previous([Rank]),[Column_1])) Rank column will assign serial numbers for each column1 section Then you can extract previous of col2 based on previous rank value. Link to comment Share on other sites More sharing options...
Clarivando Belizario Junior Posted October 4, 2019 Author Share Posted October 4, 2019 But this way it's getting the "previous" after grouping Column_1. I'd like to get the "previous" after grouping and "sorting" (or simulating sorting) columns 1 and 2. Link to comment Share on other sites More sharing options...
Khushboo Rabadia Posted October 6, 2019 Share Posted October 6, 2019 You can concatenate column1 and column2 to form a group Concatenate([Column_1],[Column_2])Then rank the values of above column in ascending order DenseRank([newcol],"asc")Then retrieve the previous value of column2 based on above ranking First([Column_2]) OVER (Intersect(Previous([newrank])))This way you will get the previous values as shown above. ------------------------------------ You can also use simple data function with TERR script like below: op Link to comment Share on other sites More sharing options...
Clarivando Belizario Junior Posted October 8, 2019 Author Share Posted October 8, 2019 Thanks! This is the solution! 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