Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Milaf
Contributor III
Contributor III

Dynamic sort is not working

Hi,

I did a dynamic sort operation with the formula below for Pivot. However, the descending or ascending ones do not work exactly correctly. Where could my error be? Or how can I solve it?

='~A-Z|'
&'sum(Quantity)~ Sort(Descending) ▼ |'
&'sum(Quantity) *-1 ~ Sort(Ascending) ▲'

Milaf_2-1716196841028.png

 

Milaf_0-1716196630440.png

Milaf_1-1716196717914.png

 

Labels (1)
1 Solution

Accepted Solutions
Milaf
Contributor III
Contributor III
Author

If you give 1 to the variable and write the following formula in the sort expression field, it works.

if(vPivotSort=1,
SUM(Quantity) ,
SUM(Quantity*-1))

View solution in original post

2 Replies
Lech_Miszkiewicz
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi, 

Your error is that you are not looking at the dimensionality of the pivot table. The sort by expression applies the same order of dimension values accross all levels based on expression used. That being said we cannot tell from your image how many dimensions you have in your pivot table. If you have multiple dimensions then sorting by measure will likely not work the way you imagine it as in Pivot table you are not able to sort dimension values based on measures independently on each nested dimension level. Instead the total sort is being used. 

The only way of actually sorting by measure values is by using "Sort by first measure" option which (yes) - is limited) to only first measure of your pivot table and yes that is the only way of actually sorting by values on all levels

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.
Milaf
Contributor III
Contributor III
Author

If you give 1 to the variable and write the following formula in the sort expression field, it works.

if(vPivotSort=1,
SUM(Quantity) ,
SUM(Quantity*-1))