Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Pick the right date base on condition

Hi,

Need some help with how can this be achieve in Qlikview

I have records as below. Basically, one policy number will have multiple transaction code. Transaction code NEW and REN will determine the DESIREDDATE for the rest of the transaction code. Sample as below.

   

Policy_numberTransaction_CodeTransaction_Date_1DESIREDDATE
HSHC000001NEW2011092620110926
HSHC000001END2013092620110926
HSHC000001REN2014092620140926
HSHC000001END2014070520140926
HSHC000001CAN2015100520140926

Any help is very much appreciated!

4 Replies
swuehl
MVP
MVP

Maybe something along these lines

INPUT:
LOAD * INLINE [
Policy_number, Transaction_Code, Transaction_Date_1,
HSHC000001, NEW, 20110926
HSHC000001, END, 20130926
HSHC000001, REN, 20140926
HSHC000001, CAN, 20151005
];

RESULT:
LOAD
*,
If(Match(Transaction_Code,'NEW','REN'), Transaction_Date_1, Peek('DESIREDDATE')) as DESIREDDATE
Resident INPUT
ORDER BY Transaction_Date_1;

DROP TABLE INPUT;

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try this slightly modified code from swuehl, we need to use Policy_number in the Order by, I think you will have multiple Policy numbers

  1. INPUT: 
  2. LOAD * INLINE [ 
  3. Policy_number, Transaction_Code, Transaction_Date_1,  
  4. HSHC000001, NEW, 20110926  
  5. HSHC000001, END, 20130926  
  6. HSHC000001, REN, 20140926  
  7. HSHC000001, CAN, 20151005  
  8. ]; 
  9. RESULT: 
  10. LOAD  
  11. *, 
  12. If(Match(Transaction_Code,'NEW','REN'), Transaction_Date_1, Peek('DESIREDDATE')) as DESIREDDATE 
  13. Resident INPUT 
  14. ORDER BY Policy_number, Transaction_Date_1; 
  15. DROP TABLE INPUT; 
Not applicable
Author

Hi Jagan,

The idea is right. But what if i need to assign the desired date to more than one row? Is there anyway to make it a running number base on the number of rows for the policy number?

Regards,

Samuel

jagan
Luminary Alumni
Luminary Alumni

Is it not working?  It will assign the data as long as it not changed to NEW OR REN,

Regards,

jagan