Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
safik003
Contributor III
Contributor III

Find records greater than certain value based on a condition

Dear All,

I have below records.

IDSeqNoTypeValue
1000104000
100115500
100220600
100310100
100418300
1010105000
101120450
101215600
101318250
101416380

 

For each ID, I want to flag those records which comes after  Type=20 and  flag them as 'Y'

For example, for ID=100, I want to take SeqNo 3 and 4 which comes after Type=20 

i,e only take those records which is greater than SeqNo=2 (for Type=20, SeqNo=2)

SeqNo is always in increasing order and integer.

Below is the desired Output

 

IDSeqNoTypeValueFlag
100310100Y
100418300Y
101215600Y
101318250Y
101416380Y

 

A sample file is attached.

Labels (1)
1 Solution

Accepted Solutions
tresesco
MVP
MVP

Try like:

Test:
LOAD * INLINE [
ID, SeqNo,Type, Value
100, 0,  10, 4000
100, 1,  15, 500
100, 2,  20, 600
100, 3,  10, 100
100, 4,  18, 300
101, 0, 10, 5000
101, 1, 20, 450
101, 2, 15, 600
101, 3, 18, 250
101, 4, 16, 380
];
t1:
Load
	ID,
	SeqNo,
	If(ID=peek('ID') and (peek('Type')=20 or Peek(Flag)='Y'), 'Y', 'N') as Flag,
	Type,
	Value
Resident Test Order by ID, SeqNo;
NoConcatenate
t2:
Load
	*
resident t1 Where Flag='Y';		

Drop table Test, t1;	

View solution in original post

1 Reply
tresesco
MVP
MVP

Try like:

Test:
LOAD * INLINE [
ID, SeqNo,Type, Value
100, 0,  10, 4000
100, 1,  15, 500
100, 2,  20, 600
100, 3,  10, 100
100, 4,  18, 300
101, 0, 10, 5000
101, 1, 20, 450
101, 2, 15, 600
101, 3, 18, 250
101, 4, 16, 380
];
t1:
Load
	ID,
	SeqNo,
	If(ID=peek('ID') and (peek('Type')=20 or Peek(Flag)='Y'), 'Y', 'N') as Flag,
	Type,
	Value
Resident Test Order by ID, SeqNo;
NoConcatenate
t2:
Load
	*
resident t1 Where Flag='Y';		

Drop table Test, t1;