Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Sorting Macro

I have to sort a table by dimension where all the selected values should come on top. What will be the macro for that ??

1 Solution

Accepted Solutions
CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     You can do it without macro.

     Use Sort by Expression in the sort Tab of the chart properties.

     =if(Match(FieldName,$(=chr(39)&GetFieldSelections(FieldName,chr(39)&','&chr(39),20)&chr(39))),0,1)

Instead of 20 you can use maximum number of field values.

Celambarasan

View solution in original post

7 Replies
d_pranskus
Partner - Creator III
Partner - Creator III

Hi

What is the type of sheet object you want this to achieve/

Darius

Not applicable
Author

the type of sheet object is straight table

d_pranskus
Partner - Creator III
Partner - Creator III

Hi

It is better to use list box for that. In QV11 it allows expressions. In this case you will have a posibility to sort selected values at the top and excluded at the bottom.

Cheers

Darius

Not applicable
Author

I can not do that. My requirement is such that i have to display the volumes of different products in one table and if i select multiple products. the selected products should be highlighted and the remaining products should also be listed there. But all the selected products should be at the top of the table.

d_pranskus
Partner - Creator III
Partner - Creator III

Hi

Try this example as starting point

Cheers

Darius

jonathandienst
Partner - Champion III
Partner - Champion III

Hi

That's not the way Qlikview normally works. Normally, list boxes will display all values, and (depending on the sort criteria) put the selected items on top. Straight tables will only display selected items, non-selected items, or items excluded by selections on other fields will not display at all.

There are some tricks to override the bahaviour in list boxes, but you cannot change the selection behaviour in straight tables.

What you can do is create an island field (eg ProductIsland in DataIsland table) for the products you want to highight. Display this in a list box so you can make select products to highlight.

  • Define a variable vTest:

=chr(39) & GetFieldSelections(ProductIsland, chr(39) & ',' & chr(39), 10) & chr(39)

(where 10 is the maximum number of selections to allow)

  

  • Click the + sign next to the expression to highlight, and select foreground or background colour:

Enter an expression something like:

     eg for background:

     If(Dimensionality()>0 And Match(Product, $(vTest)) <> 0, Yellow())

  • And in the sort, enter an expression like (to sort by product), or enter a hidden column and sort by that column (before hiding it). Also disable interactive sorting:

     If(Match(Product, $(vTest)), 'z', 'a') & Product

See the attached.

Regards

Jonathan

Edit: Darius' example is better than mine, I think

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     You can do it without macro.

     Use Sort by Expression in the sort Tab of the chart properties.

     =if(Match(FieldName,$(=chr(39)&GetFieldSelections(FieldName,chr(39)&','&chr(39),20)&chr(39))),0,1)

Instead of 20 you can use maximum number of field values.

Celambarasan