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: 
alan_grn
Creator II
Creator II

Finding the last item

I am trying to create a load script and want to be able to find the last order for a customer.

I want to pass the cutomer id and return the order number of the last order for that customer.

How do I do this?

3 Replies
Not applicable

I would go with max(orderdate) and use a group by customer etc. Do you have an example?

alan_grn
Creator II
Creator II
Author

Thanks this should work if I create a table by loading the max values in to it.

What I am trying to do as part of a load script is for a customer ID (while loading table 2) find the last order for that customer (from table1 whihc has cust Id and order id) and load it in to the table that I am loading. (table 2)

Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

I'd recommend using function FirstSortedValue to get the last Order, then creating a mapping table, to map CustomerId to theLastOrderID, and use the map when you load your table 2. Something like the following:


LastOrderMap:
mapping load
CustomerID,
FirstSortedValue(distinct OrderID, OrderDate * -1) as LastOrder // Multiplying Date by -1 causes the LAST order to be returned
resident
Table1
group by
CustomerID
;
Table2:
load
CustomerID,
...
ApplyMap('LastOrderMap', CustomerID, null()) as LastOrder
resident
...


cheers,

Ask me about Qlik Sense Expert Class!