Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Sorting within set analysis expresssion?

Sorry to re-open but I'm still stuck on this a bit.

The sample you provided taught me a lot but giving a scenario where the sample table is being generated by a set analysis in the text box instead of being the raw table data. Is there a way to sort the data by certain columns, within the textbox set analysis expression?

: Assuming that the actual data table is much large.

Type

Item

RankValueTextBreak
A21199AA5
A2280BB5
B21188AA7
B2385BB8
A15280CC6
A4377DD5
A8460EE8

Using set analysis filter by <Type = {'A'}>

Type

Item

RankValueTextBreak
A21199AA5
A2280BB5
A15280CC6
A4377DD5
A8460EE8

Inside a text box expression, the following

=only({<Type = {'A'}, Item = {"=rank(sum(Only(<{Type = {'A'}}>Value)),4)=2"}>}Text)

should give me the result : BB

The question:

What if i want the sorting to be by column 'Break' when there is a tie breaker in the 'Value' column.

ie. when both Item 2 and Item 15 have the same Value 80, i want the higher Break to be on top.

Is there a way, using set analysis to make working table data be sort like this ?

Type

Item

RankValueTextBreak
A21199AA5
A15280CC6
A2280BB5
A4377DD5
A8460EE8

I'm expecting the Text Box to show the Text 'CC' for rank() = 2.

6 Replies
Not applicable
Author

Try this

=SubField(Concat({<Type={'A'},Rank={2}>}Text,',',-Break),',',1)

Not applicable
Author

Thanks, Devang, still new to qlikview, though I figure the concept behind your code,

but that wont work for me, since its a static code.

For my situation, the data is unknown and handling tie breakers manually like that isnt possible, since i cannot determine when there will be a tie in ranks. It will not be possible to know which field to subField by, 1st, 2nd , 3rd, etc.

Not applicable
Author

This always will give you Text with highest Break. If you want to display in text box, what is your specific requirement.

Sample output with each Type,rank,text, break combination so that someone will be able to help you.

Not applicable
Author

i'm trying to retrieve the text of all the top ranks regardless of ties, so for this sample, 5 text boxes of the top 5 rank text.

After filtering by type, Item number is the unique row identifier sorted by Rank to get the text.

The output sorts by Alpha default on the text, since that is the output.

The output im expecting is the last sample table i listed.

txtbox1 --> AA

txtbox1 --> CC

txtbox1 --> BB

txtbox1 --> DD

txtbox1 --> EE

Not applicable
Author

hi Jun,

You can create a sorting column in the sample table based on the other columns in a table in which you get a unique row identifier and you can use rank function on the sorted column.

Thanks

Nandkishor Suresh Pandirkar

Not applicable
Author

is there no alternative to this ?

I'm trying to avoid this due to large data table and specific data set ranking.

The current file im working with has 250K+ rows with 30+ columns and of these, about everything 50~70 rows is a subset of data by itself that can be rank sorted. And based on the ranking type, the same set of data can be ranked differently based on a different view.

Pre-calculating everything wouldn't be efficient, since not everything requires rank sorting.