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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Set a FINAL month flag for each account during load

Hi All,

I have some data that looks like this:

AccountDue Date
AZ000305/06/2010
AZ000305/07/2010
AZ000305/08/2010
AZ000305/09/2010
AZ000305/10/2010
AZ000305/11/2010
ZZ009925/06/2010
ZZ010025/07/2010
ZZ010125/08/2010
ZZ010225/09/2010
XD003314/06/2010
XD003414/07/2010
XD003514/08/2010
XD003614/09/2010
XD003714/10/2010
XD003814/11/2010


During the load is there a best practice way to identify the final month for each account and set the status to FINAL for the last record and LIVE for the others, so the data would look like this after the load:

AccountDue DateStatus
AZ000305/06/2010LIVE
AZ000305/07/2010LIVE
AZ000305/08/2010LIVE
AZ000305/09/2010LIVE
AZ000305/10/2010LIVE
AZ000305/11/2010FINAL
ZZ009925/06/2010LIVE
ZZ010025/07/2010LIVE
ZZ010125/08/2010LIVE
ZZ010225/09/2010FINAL
XD003314/06/2010LIVE
XD003414/07/2010LIVE
XD003514/08/2010LIVE
XD003614/09/2010LIVE
XD003714/10/2010LIVE
XD003814/11/2010FINAL


I guess I could sort the data by account ascending and by date descending then use peek, so if that if account<>peek(account) then FINAL else LIVE... but just wondered if there's a better way?

Many thanks,
Phil

1 Solution

Accepted Solutions
Not applicable
Author

Hi,

Check the attached application.

Your script should be as follow.


Test:
Load Account, date(date#([Due Date],'DD/MM/YYYY')) as Date,left(Account,2) as Account_new;
Load * Inline [
Account, Due Date
AZ0003, 05/06/2010
AZ0003, 05/07/2010
AZ0003, 05/08/2010
AZ0003, 05/09/2010
AZ0003, 05/10/2010
AZ0003, 05/11/2010
ZZ0099, 25/06/2010
ZZ0100, 25/07/2010
ZZ0101, 25/08/2010
ZZ0102, 25/09/2010
XD0033, 14/06/2010
XD0034, 14/07/2010
XD0035, 14/08/2010
XD0036, 14/09/2010
XD0037, 14/10/2010
XD0038, 14/11/2010
];
Left Join
Load Account_new,
date(Max(Date)) as Date,
'FINAL' as Status
Resident Test
group by Account_new;
Noconcatenate
Test1:
Load Account,
Date,
Account_new,
if(len(Status)<=0,'LIVE',Status) as Status
Resident Test;
Drop Table Test;






Hope this may help you.

-Peterson







View solution in original post

2 Replies
Not applicable
Author

Hi,

Check the attached application.

Your script should be as follow.


Test:
Load Account, date(date#([Due Date],'DD/MM/YYYY')) as Date,left(Account,2) as Account_new;
Load * Inline [
Account, Due Date
AZ0003, 05/06/2010
AZ0003, 05/07/2010
AZ0003, 05/08/2010
AZ0003, 05/09/2010
AZ0003, 05/10/2010
AZ0003, 05/11/2010
ZZ0099, 25/06/2010
ZZ0100, 25/07/2010
ZZ0101, 25/08/2010
ZZ0102, 25/09/2010
XD0033, 14/06/2010
XD0034, 14/07/2010
XD0035, 14/08/2010
XD0036, 14/09/2010
XD0037, 14/10/2010
XD0038, 14/11/2010
];
Left Join
Load Account_new,
date(Max(Date)) as Date,
'FINAL' as Status
Resident Test
group by Account_new;
Noconcatenate
Test1:
Load Account,
Date,
Account_new,
if(len(Status)<=0,'LIVE',Status) as Status
Resident Test;
Drop Table Test;






Hope this may help you.

-Peterson







Not applicable
Author

Hi Kevin,

Thank you very much for that, it does exactly what I need... I was working towards loading the max date by account and joining it but your solution does everything much more efficiently.

Many thanks,
Phil