Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik and ServiceNow Partner to Bring Trusted Enterprise Context into AI-Powered Workflows. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
D19PAL
Creator II
Creator II

Create a field from table 1

Hi Guys,

I want to add a before_ and_ After field to my table, preferbly joined or built in the first table.  

Here is the code to create the field, feel free to change it if needed.

 if(Date 1 = order date, 'Before',if(Date 1 < order date,'After )) as [Before_or_After]
 
How original table is
 
Name, Date 1, order date, Id 
John 01/01/2010 01/01/2010 1 
John 01/01/2010 01/01/2010 1 
John 01/01/2010 01/01/2010 1 
John 01/01/2010 05/01/2010 2 
John 01/01/2010 05/01/2010 2 
John 01/01/2010 05/01/2010 2 
Paul 01/01/2010 01/01/2010 3 
Paul 01/01/2010 01/01/2010 3 
Paul 01/01/2010 01/01/2010 3 
Paul 01/01/2010 05/01/2010 4 
Paul 01/01/2010 05/01/2010 4 
Paul 01/01/2010 05/01/2010 4 
    
    
    How I want the table, for every Name and Id, I want it to tell me only in the first row if it's before or after.
    
    
Name, Date 1, order date, Id, Before_or_After
John 01/01/2010 01/01/2010 1 Before
John 01/01/2010 01/01/2010 1 
John 01/01/2010 01/01/2010 1 
John 01/01/2010 05/01/2010 2 After
John 01/01/2010 05/01/2010 2 
John 01/01/2010 05/01/2010 2 
Paul 01/01/2010 01/01/2010 3 Before
Paul 01/01/2010 01/01/2010 3 
Paul 01/01/2010 01/01/2010 3 
Paul 01/01/2010 05/01/2010 4 After
Paul 01/01/2010 05/01/2010 4 
Paul 01/01/2010 05/01/2010 4 
 
Thanks
3 Replies
Saravanan_Desingh

Try this,

tab1:
LOAD RowNo() As RowID,*, 
	If(Peek(Id)<>Id, If(Odd(Id),'Before','After')
	) As Before_or_After;
LOAD * INLINE [
    Name, Date 1, order date, Id
    John, 01/01/2010, 01/01/2010, 1
    John, 01/01/2010, 01/01/2010, 1
    John, 01/01/2010, 01/01/2010, 1
    John, 01/01/2010, 05/01/2010, 2
    John, 01/01/2010, 05/01/2010, 2
    John, 01/01/2010, 05/01/2010, 2
    Paul, 01/01/2010, 01/01/2010, 3
    Paul, 01/01/2010, 01/01/2010, 3
    Paul, 01/01/2010, 01/01/2010, 3
    Paul, 01/01/2010, 05/01/2010, 4
    Paul, 01/01/2010, 05/01/2010, 4
    Paul, 01/01/2010, 05/01/2010, 4
];
Saravanan_Desingh

Output:

commQV40.PNG

D19PAL
Creator II
Creator II
Author

This was a sample data, hasn't worked with my real data.  I'm getting  before for each row and nothing for after.