Using Rank() with Aggr
The Rank()
function is likely used to calculate the relative position of the value on the dimension of the chart, starting from 1 to N.
As Rank()
requires a dimension in the object to calculate the relative position, how can we use it in a text object to show the name of the top five countries with more sales?
This recipe will show you how to use Rank()
with Aggr
to get this top five visualization in a dimensionless object.
Getting ready
For this recipe, we will reuse the data load for the Using nestedaggregations recipe of this chapter.
How to do it…
- Drag a
Text & image
object onto the content area. - Add the following text:
Top 5 Customers
, and type Enter to create a new line. - Format the text as bold.
- Go to the property editor and open the
Data
section. - Add a new measure with the following expression:
=concat( aggr( if (rank(sum(Sales)) <= 5, Country), Country) , ',', aggr(rank(sum(Sales)),Country) )
The result will look like the following screenshot...