Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Loading max date entry?

Hi

I am having a problem where I am trying to load monthly customer files and customers appear in more than one monthly file but sometimes with updated names etc. So I am trying to load the Customer ID and the Customer Names but only from the file with the latest date that each customer appears in. I have got it to the point where I have a date and I am using a peek function I am just not sure how to use the date in the peek function so that it gives me what I want. So in the excel block below I only want to load the last line:

CustomerIDCustomer NameFileDates
100535Store A01.01.2013
100535Store A01.02.2013
100535Store A01.03.2013
100535Store A01.04.2013
100535Store A01.05.2013
100535Store A01.06.2013
100535Store A01.07.2013
100535Store A01.08.2013
100535Store A01.09.2013
100535Store A01.10.2013
100535Store A01.11.2013
100535Store B01.12.2013

I am using the following script but it is not working 100% - does anyone have any suggestions?

LOAD FileDates,

  CustomerID,

  if(peek(CustomerID)=CustomerID and FileDates < peek(FileDates),Null(),[Customer Name]) as [Customer Name]

RESIDENT Customers

order by CustomerID, FileDates ASC;

Thanks

1 Solution

Accepted Solutions
Peter_Cammaert
Partner - Champion III
Partner - Champion III

Use FirstsortedValue() to get the most recent Customer Name. You can use something like:

LOAD CustomerID, FirstSortedValue(CustomerName, -num(FileDates)) AS CustomerName

RESIDENT CUSTOMERS

GROUP BY CustomerID;

Make sure that FileDates contains a QlikView date field (e.g. string & numerical representation).

Peter

View solution in original post

4 Replies
Peter_Cammaert
Partner - Champion III
Partner - Champion III

Use FirstsortedValue() to get the most recent Customer Name. You can use something like:

LOAD CustomerID, FirstSortedValue(CustomerName, -num(FileDates)) AS CustomerName

RESIDENT CUSTOMERS

GROUP BY CustomerID;

Make sure that FileDates contains a QlikView date field (e.g. string & numerical representation).

Peter

Not applicable
Author

PFA

Not applicable
Author

Thanks Peter that works perfectly!

Peter_Cammaert
Partner - Champion III
Partner - Champion III

FirstSortedValue() is a great function for another problem. Imagine that for every Customer ID you want to list the last CustomerName AND some details that belong to the same specific record. A GROUP BY doesn't allow you to grab details that aren't aggregated or present in the GROUP BY clause.

FirstSortedValue() fixes that because you can get the details from that same record (with the most recent name) by repeating the FirstSortedValue() expression on additional fields.

I'm sure you'll encounter a situation like that sooner or later.

Peter