Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
razvan_brais
Creator III
Creator III

Getting the latest customer name in loading script

Hi guys ,

 I need some help. 

 I need to get the latest customer name from a table. I need to do this in loading script. 

The data looks something like this:

Customer IDCustomer NameReporting date
1Test101/12/2019
1Test201/01/2020
2Test401/11/2019
2Test301/02/2020

 

The result should be this:

Customer name : Test2 and Test3 because those names are the latest.

Can you please help me?

Thank you,

Razvan

1 Solution

Accepted Solutions
lironbaram
Partner - Master III
Partner - Master III

Hi 

your script can look like this :

Table:
Load Customer ID,
     Customer Name,
     Reporting date
From XXX;
//////////finding the max date for customer////
CustomerTemp:
load Customer ID,
     max([Reporting date]) as Reporting date
resident Table
group by [Customer ID];
left join (CustomerTemp)
load Customer ID,
     Customer Name
resident Table;

///////////////adding the latest name to main table 
left join (Table)
load [Customer ID],
     [Customer Name] as CustomerUpdateName
resident CustomerTemp;

drop table CustomerTemp;

View solution in original post

4 Replies
lironbaram
Partner - Master III
Partner - Master III

Hi 

your script can look like this :

Table:
Load Customer ID,
     Customer Name,
     Reporting date
From XXX;
//////////finding the max date for customer////
CustomerTemp:
load Customer ID,
     max([Reporting date]) as Reporting date
resident Table
group by [Customer ID];
left join (CustomerTemp)
load Customer ID,
     Customer Name
resident Table;

///////////////adding the latest name to main table 
left join (Table)
load [Customer ID],
     [Customer Name] as CustomerUpdateName
resident CustomerTemp;

drop table CustomerTemp;
tresesco
MVP
MVP

Try using firstsortedvalue().

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I would typically script it like this. Assume your data has already been loaded into a table named "Customers"

Inner Join (Customers)
LOAD
  [Customer ID],
  max([Reporting date]) as [Reporting date]
Resident Customers
Group by [Customer ID]
;

-Rob
http://masterssummit.com
http://qlikviewcookbook.com
http://www.easyqlik.com

razvan_brais
Creator III
Creator III
Author

Hy all. Thank you for your help.

 I used @lironbaram solution and it worked. 

 Thank you again.

Razvan