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

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

aggr() function issue

Hi guys,

I got some questions about aggr() function,I have a sales table just looks like below:

yearidcustiditemidpurchaseidamt
2013Aitem115
2012Aitem2210
2008Aitem3315
2006Aitem4420
2013Bitem2510
2013Bitem3615
2012Bitem2720
2018Bitem1825
2013Citem195
2008Citem21010
2007Citem31115
2006Citem51220
2013Ditem51311

What I need is to calculate what items each customer has bought before they first buy the item item2, just look like:

yearidcustiditemidAMTmin_year_item2statuscombined_item
2008Aitem3152012YESitem3+item4
2006Aitem4202012YESitem3+item4
2007Citem3152008YESitem3+item5
2006Citem5202008YESitem3+item5
2013Aitem152012NOitem1+item2
2012Aitem2102012NOitem1+item2
2018Bitem1252012NOitem1+item2+item3
2013Bitem2102012NOitem1+item2+item3
2012Bitem2202012NOitem1+item2+item3
2013Bitem3152012NOitem1+item2+item3
2013Citem152008NOitem1+item2
2008Citem2102008NOitem1+item2

Thanks for your help.

1 Solution

Accepted Solutions
Not applicable
Author

I don't really understand what you are trying to achieve. You want to know what items a customer has bought before he first buys item2. Then why do you expect an output for customer B?

Anyway, try:

Concat(TOTAL <custid> Aggr(If(yearid < (Aggr(NODISTINCT Min({$ <itemid={'item2'}>} yearid),custid)),Only(itemid)),custid,yearid),'+')

View solution in original post

6 Replies
vikasmahajan

PFA

Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution & like it.
If you want to go quickly, go alone. If you want to go far, go together.
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

I think you should solve this in the script. See attached example.


talk is cheap, supply exceeds demand
Not applicable
Author

Thanks, but what I need is the expression: combined_item,

finally it should be shown as below:


yearidcustiditemidmin_year_item2combined_item
2008Aitem32012item3+item4
2006Aitem42012item3+item4
2007Citem32008item3+item5
2006Citem52008item3+item5
2013Aitem12012item1+item2
2012Aitem22012item1+item2
2018Bitem12012item1+item2+item3
2013Bitem22012item1+item2+item3
2012Bitem22012item1+item2+item3
2013Bitem32012item1+item2+item3
2013Citem12008item1+item2
2008Citem22008item1+item2


Not applicable
Author

I don't really understand what you are trying to achieve. You want to know what items a customer has bought before he first buys item2. Then why do you expect an output for customer B?

Anyway, try:

Concat(TOTAL <custid> Aggr(If(yearid < (Aggr(NODISTINCT Min({$ <itemid={'item2'}>} yearid),custid)),Only(itemid)),custid,yearid),'+')

Not applicable
Author

Thanks,but the min_year_item2 is changed when different period time is selected,so I use the expression:

aggr(NODISTINCT min({<itemid={'item2'}>} yearid),custid) .

Is there any other solution?

Not applicable
Author

Thanks Dirk, it works.