Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

First Sorted Value - Repeat Rows / Rank Issue

Dear all,

I have found most of the solution to the below problem from other community pages but am struggling with the final part, help would be much appreciated!

I am trying to create a table which shows the sequence of investment by clients using a historical track record month by month. The first part of the challenge was to remove repeat values (using DISTINCT in FirstSortedValue) but now I have the issue that in some months there are two new investments and I think the FSV is unable to tell between them. I would be happy to rank them within the month by the size but this is where I fail.

Abridged example of the input data (in bold example of the first situation where there is a repeat value)

    

CLIENTMONTHPRODAMOUNT
ACCOUNT01/05/2016EQ       211,720
ACCOUNT01/06/2016CM    1,312,114
ACCOUNT01/06/2016EQ       582,959
ACCOUNT01/06/2016FI    1,300,500
ACCOUNT01/07/2016CM    1,267,931
ACCOUNT01/07/2016EQ       604,172
ACCOUNT01/07/2016FI    1,296,814
ACCOUNT01/08/2016CM    1,268,735
ACCOUNT01/08/2016EQ       629,561
ACCOUNT01/08/2016FI    1,293,994
ACCOUNT01/09/2016CM    1,269,440

In setting this up I created a sub table with just the min values which makes me thing the rank is the problem based on RANK function

     

CLIENTPRODSUM(AMOUNT)MIN_MONTHRANK
ACCOUNTEQ7,643,94201/05/20161
ACCOUNTCM27,634,98901/06/20162-3
ACCOUNTFI26,143,48801/06/20162-3
ACCOUNTMF3,863,17101/10/20164

As an output I am trying to create a new table with the first, second and third investments made, using the code:

First Value Example:

FirstSortedValue(

DISTINCT PROD,

AGGR(MIN(MONTH),PROD, CLIENT),

1

)

Second Value Example:

FirstSortedValue(

DISTINCT PROD,

AGGR(MIN(MONTH),PROD, CLIENT),

2

)

etc.

So in this example, I would expect the result table to look like this:

CLIENTFirst InvestSecond InvestThird InvestFourth Invest
ACCOUNTEQCMFIMF

I may be totally off track and there is an easier way to do this!

Thanks,

Ben

1 Solution

Accepted Solutions
sunny_talwar

May be try like this

FirstSortedValue(DISTINCT PROD, Aggr(((Min(MONTH)*1E2)-(Sum(AMOUNT)/1E10)),PROD, CLIENT), 2)

View solution in original post

3 Replies
sunny_talwar

May be try like this

FirstSortedValue(DISTINCT PROD, Aggr(((Min(MONTH)*1E2)-(Sum(AMOUNT)/1E10)),PROD, CLIENT), 2)

Anonymous
Not applicable
Author

Thanks Sunny - that does work!

Quick question though - is the use of 1E2 and 1E10 by way of scaling the results so when they are combined you get the correct order? I.e. 1E2 makes the month figure large and /1E10 makes the amount small?

sunny_talwar

Quick question though - is the use of 1E2 and 1E10 by way of scaling the results so when they are combined you get the correct order? I.e. 1E2 makes the month figure large and /1E10 makes the amount small?

You are absolutely correct .