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: 
datagrrl
Creator III
Creator III

How to get the first N - using a string function - dimension value

This seems simple, but it is evading me this morning.

 

datagrrl_0-1677856631505.png

If I want to see the "Top 2" or "bottom 2"  (or whatever number) alphabetically (nothing to do with the measures) how would I do that?  In my example I only want to see Mexico and the USA, but if Turkey was added I would want to see Turkey and the US. I want to see the last two alphabetically.

This is a dummy example, and I included my dummy file. 

Any assistance is appreciated.

 

 

Labels (1)
1 Solution

Accepted Solutions
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi Datagrrl,

This is a tricky one... Since Dimension Limits can only be applied to the first Measure, which is Sales, there is no easy way of limiting the chart to the top (bottom) entries in the alphabetical order. 

The only way is to limit the data in the Measure using Set Analysis. I managed to get the last two countries (Mexico and US) with the following formula. For other situations, you may need to tweak it a bit, but you can see the general direction:

Sum({<Country={"=rank(Country)<=2"}>} Sales)

To my great surprise, the function Rank() appears to work for strings as well!

Cheers,

View solution in original post

2 Replies
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi Datagrrl,

This is a tricky one... Since Dimension Limits can only be applied to the first Measure, which is Sales, there is no easy way of limiting the chart to the top (bottom) entries in the alphabetical order. 

The only way is to limit the data in the Measure using Set Analysis. I managed to get the last two countries (Mexico and US) with the following formula. For other situations, you may need to tweak it a bit, but you can see the general direction:

Sum({<Country={"=rank(Country)<=2"}>} Sales)

To my great surprise, the function Rank() appears to work for strings as well!

Cheers,

datagrrl
Creator III
Creator III
Author

Thanks, this worked. Weird that I had to add an extra one, but I am guessing that Null or blank must be ranked at the end in my real data set (needs cleaning).