Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
Jennell_McIntire
Employee
Employee

Over the years, I have seen the Rank function used in various expressions.  Recently, I was working on a Broadway Shows project where we wanted to show the rank in a bar chart before the label adding a numeric indicator of how a show ranked.  You can see what I am referring to in the bar charts used in the Broadway app.  The bar chart below is an example of one of the charts.  We added the rank before the show name on the y-axis label.

Broadway.png

In this blog, I will discuss how the Rank arguments can be used to change how the rank is presented.  To do so, I will use a simplified data set to illustrate how the rank can be displayed.  Let’s start by defining the Rank function.  The Rank function is a chart function and is defined in Qlik Sense Help as:

 

Rank() evaluates the rows of the chart in the expression, and for each row, displays the relative position of the value of the dimension evaluated in the expression. When evaluating the expression, the function compares the result with the result of the other rows containing the current column segment and returns the ranking of the current row within the segment.

 

For charts other than tables, the current column segment is defined as it appears in the chart's straight table equivalent.

 

Syntax:

Rank([TOTAL] expr[, mode[, fmt]])

 

Originally, I used the Rank function without any arguments.  This will rank the products by their sales and display it before the product label.

Rank no arguments.png

Rank no arguments chart.png

By default, with no arguments for mode and fmt, the Rank function will show the lowest and highest value displayed like a range as seen in the chart above.  But what if you want to show a single number for the rank where Product_B and Product_J would show 1 as the rank for both projects since they both tied for first place.  This can be accomplished by using the mode and fmt arguments.  Mode can take values 0 – 4 and controls which rank is shown for each row for example show the lowest rank, the average rank or the highest rank.  The fmt argument takes values 0 – 2 and controls how and where the rank is displayed.  You can find the detailed description for each setting in Qlik Sense Help.

 

For the Broadway app, I set the mode to 4 and the fmt to 1.  If I do this with this data set, I will get a chart like this:

Rank arguments.png

Rank arguments chart.png

The mode argument is 4. This will show the lowest rank on the first row, then increment by one for each row.  The fmt argument is 1 and this will show the low value on all rows.  When there is a tie, only the lowest rank will be displayed on the respective rows.

 

There are not always ties when using the Rank function but when there are, the Rank function provides options for how to handle the display of the rank.  This was something I never had a need for until now but I found it to be very valuable so I thought I would share what I have learned.  The next time you use the Rank function, try out the various arguments to find the display that works best for your app.

 

Thanks,

Jennell

20 Comments
passionate
Specialist
Specialist

good and simplified article.

Thanks for sharing

0 Likes
30,588 Views
Anonymous
Not applicable

Another great explanation for a key function.  Especially valuable to illustrate some of the options for Mode and Format (fmt) parameters.  ...Of course, as noted, some of this is in online help too, but to have these examples helps so much to grasp some concepts.

0 Likes
30,588 Views
paulyeo11
Master
Master

Question on Design Blog from Jennell on Ranking.

Hi Jennell

your post are alway interesting. I have try your expression , i encounter some problem , kindly help by take a look of above link.

Paul

0 Likes
30,588 Views
Jennell_McIntire
Employee
Employee

Hi Paul,

Your dimension should be:

=Aggr(Rank(Sum(sales), 4, 1), BRAND_) & '. ' & BRAND_

And you measure should be:

Sum(sales)

I tried that and it worked for me.

Jennell

0 Likes
30,588 Views
paulyeo11
Master
Master

June 2017 Version does not allow me turn on value amount on individual bar

Hi Jennell

Thank you very much for your advise , i notice that all your bar chart able to display value on the bar . I am unable to make the sales amount display on the bar , kindly take a look on the above link , Hope you can advise me where i go wrong ?

Paul

0 Likes
30,588 Views
Jennell_McIntire
Employee
Employee

Paul,

In the Properties window under Appearance > Presentation > Turn "Value labels" on/to Auto.

Jennell

0 Likes
30,588 Views
paulyeo11
Master
Master

Hi Jennell

In my attach QVF , I am unable locate the Properties windows . ( the old version it have ) .

May be you are using old version ? It is possible for you to use June 2017 version ?

Paul Yeo

DIrector

TDS Technology (S) P/L

Whatsapp +65 9326 1804

www.tdstech.com<http://www.tdstech.com>

0 Likes
24,296 Views
Jennell_McIntire
Employee
Employee

Hi Paul,

I am using the June 2017 release.

Maybe your properties pane is toggled off.  Try clicking the image in the bottom right to open the properties pane.  Properties icon looks like this:

Properties icon.png

0 Likes
24,296 Views
paulcalvet
Partner - Specialist
Partner - Specialist

Hi Jennel,

There is a little bug on the broadway Mashup.

If you search a value in the table, the list appears on the top of the page :

Broadway2.pngBroadway1.png

Regards,

Paul

0 Likes
24,296 Views
Jennell_McIntire
Employee
Employee

Thanks for the heads up Paul C.  We will have a look at this.

0 Likes
24,296 Views