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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
jim_chan
Specialist
Specialist

I have problem using Previous Function

Dear all, 

I am not sure how to use the Previous function in my requirement. 

Ok. i have a list of data, same ID but activated date and main key is different. jim_chan_0-1621865900132.png

I expected result is:

1) Only load out the ID with latest activated_dt - mean in my data should only keep 26/1 records, and get rid of the old one -  actviated dt on 22 jan.

2) the actual data is daily transaction, can have millions of records. user just want each ID to have 14 days of records only. 

jim_chan_1-1621866111655.png

However, i have tried to use Previous Function, but ended up only able to get this. So, i would really need your guys help again.

jim_chan_2-1621866170518.png

I have my sample qvw and data as per attached.

 

 

 

Labels (1)
6 Replies
QFabian
MVP
MVP

Hi @jim_chan , please check this :


DATA:
LOAD
MAIN_KEY & ' | ' & ID as %_Key,
MAIN_KEY,
ID,
DATED_DT,
ACTIVATED_DT,
TOTAL_GB
FROM test_2subs_key.csv (txt, utf8, embedded labels, delimiter is ',', msq)
Where
DATED_DT >= (today()-14);

LATEST_RECORD:
Load
%_Key,
max(ACTIVATED_DT) as Max_ACTIVATED_DT
Resident DATA
Group By
%_Key;


exit script;

Greetings!! Fabián Quezada (QFabian)
did it work for you? give like and mark the solution as accepted.
jim_chan
Specialist
Specialist
Author

Dear fabian,

Thanks for the script.

Can you tell me why use where clause -DATED_DT >= (today()-14);

In actual data, there are line of records from dated date 1 Jan 2021. By
applying this clause, does it means those with 1 Jan 2021 data will not be
loaded?

Rgds

Jim chan
QFabian
MVP
MVP

Hi @jim_chan , -DATED_DT >= (today()-14); it ia going to load records with that date from the last 14 days. Maybe you need another date field to use it, just change it

Greetings!! Fabián Quezada (QFabian)
did it work for you? give like and mark the solution as accepted.
jim_chan
Specialist
Specialist
Author

Hi @QFabian , thanks for your reply!

I have tried to change the where clause to - DATED_DT - ACTIVATED_DT <= 14; 

but the old record come out again.  ID with main key - 1111111_0

jim_chan_0-1621905528570.png

 

where should i change it?

 

Rgds

Jim

 

jim_chan
Specialist
Specialist
Author

hi @QFabian , 

because my expected result is  to load only 14 days of data from the activated_dt (26/1/2021) . 

jim_chan_0-1621905986119.png

rgds 

 

jim

jim_chan
Specialist
Specialist
Author

hi @QFabian ,

sorry, not able to provide me the expected result.  Hopefully, there are more replies on this issue.

rgds

Jim