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: 
Not applicable

FirstSortedValue issue

Hi everyone! I would like to get the first product sold to each customer , based on the date of the transaction. The problem is that when more than one products have been sold to a customer on the same date, function FirstSortedValue(ItemCode,DateT) returns null. In that case, I would like to get all the products.

Any ideas?

1 Solution

Accepted Solutions
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

That cannot be done with expressions alone. You'll have add some things in the script. Join the original table with:

join(Original)

Load CustomerCode, min(DateT) as DateT, 1 as Flag

resident Original

Group By CustomerCode;

Then you can use as expression only({<Flag={1}>}ItemCode)


talk is cheap, supply exceeds demand

View solution in original post

8 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Something like: FirstSortedValue(aggr(concat(ItemCode,', ')DateT,CustomerID),DateT)


talk is cheap, supply exceeds demand
Not applicable
Author

Unfortunately, this doesn't work....

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Please post an example document.


talk is cheap, supply exceeds demand
Not applicable
Author

As you can see from the attachment, FirstSortedValue doesn't show records for customer James as he bought 2 products the first date (day 2). I would like to get two records, showing both products for customer James.

Thank you in advance for your help,

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

FirstSortedValue(aggr(Concat(ItemCode,'|'),CustomerCode,DateT),aggr(DateT,DateT,CustomerCode))


talk is cheap, supply exceeds demand
Not applicable
Author

Thank you Gysbert, but what I would like is for Customer James to get two records instead of concatenated the two product codes on one record. The reason for that is that I want to count how many customers bought each product for the first time. Hope I was descriptive enough 🙂

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

That cannot be done with expressions alone. You'll have add some things in the script. Join the original table with:

join(Original)

Load CustomerCode, min(DateT) as DateT, 1 as Flag

resident Original

Group By CustomerCode;

Then you can use as expression only({<Flag={1}>}ItemCode)


talk is cheap, supply exceeds demand
Not applicable
Author

Thank you very much!