Category

Monday, March 24, 2014

Custom Sort in Qlikview

In one of my dashboards,  user asked me to create a pivot table that displays assets for top 10 dimension values and everything else grouped and displayed under 'Other'. So, at most the pivot table will have 11 values displayed in the dimension. This requirement can easily be achieved by creating calculated dimension using aggr () and rank () function as explained in my earlier post.
However, the tricky part was the custom sorting requirement. The dimension values need to be sorted in alphabetical ascending order but 'Others' should to be the last value.
After trying several work arounds, I solved custom sorting requirement using match () function. Under Sort tab in chart properties, selected Expression and  used following expression:

Match (aggr (if (rank(sum (Assets))<=10, Currency,'Others'), Currency),'1','2','3','4','5','6','7','8','9','10','Others')


I also selected Text A -> Z.

As you may know, Match() takes input string (aggr() expression in this case) and range of values. It returns the position of the input string in the range values. If the string is not found, it returns 0. In this scenario, it simply returns 11 for 'Others' and 0 for everything else.

This made 'Others' to be sorted as last value (11th position) and everything else is sorted in alphabetical order.

Custom sorting in Qlikview can also be achieved by creating an inline table with 2 columns, containing dimension value (same name as actual dimension column) and sort order ( numeric column with sort order numbers).  Qlikview associates dimension column with actual dimension in the data model. While sorting in UI, we can select expression and use the sort order column from the inline table for custom sort order. 
But , this was a different case as the dimension values are constantly changing and too many dimensions to code the inline table.

Feel free to comment if you know any other alternative or better solutions

11 comments:

  1. Hello Krishnamurthy,

    its a good thought, my other approach would be

    =aggr(if(rank(sum(Sales))<=10,rank(Country),11),Country)


    Srinivas Chitrapu

    ReplyDelete
  2. I think there is a need to provide some more information about Qlik and its other aspects.It is the best tool for solving some very complex IT problems.

    Qlik Rest Api Connection

    ReplyDelete