Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

COUNT of AGGR of second minimum when one field <> another field

The master table contains the following columns:  "Trans_Id", "Field1", "Field2", "Field3" and CP

I have created a INPUTFIELD column "USER_CP_SELECT". The table contains "Field1" and "USER_CP_SELECT" where user can enter the "CP" he wants to exclude from the calculations. (USER_CP_SELECT could be NULL or may different for each "Field1").

Now I want to find out for each "Field1" count of distinct "Field2" which has 2 or more "Trans_Id"  where "Field3" <=100 and "CP" <> USER_CP_SELECT

Here I want to create a for trend graphs for "Field1".

Chart Dimension is "Field1"

COUNT(DISTINCT AGGR(MIN({<Field3={'<=100'},CP={"=CP<> USER_CP_SELECT"}>}Trans_Id, 2), Field2, Field2, Field1))

Above expression works if I have selected only one value in "Field1", but does not work when multiple values are selected in "Field1".

Then I tried the below expression which works fine for multiple "Field1" selections but only finds FIRST minimum and I don't know how to find SECOND minimum.

COUNT(DISTINCT AGGR(MIN(if(Field3 <=100 AND CP <> USER_CP_SELECT,Trans_Id)), Field2, Field2, Field1))

Can someone help solve this problem?

Let me know if you need more data.

Thanks in Advance!

2 Replies
Not applicable
Author

To find the second minimum you can use rank function.For example if want to find the second minimum of sales based on country you can use it like

=aggr(min(sales,2),country)

Not applicable
Author

Yes, I know how to use simple aggr to find second minimum, but my question is different.