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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Sort by expression

As you can see I have created a bar chart.
Now suppose that I want to order the Sales expression in ascending (like the example) but the Cost expression in descending order.

how can I do this ?
as you can see the dimension is the category, and I don't need to change the sort rule on the dimension but on the expression.

Thanks a lot.

Bye

9 Replies
disqr_rm
Partner - Specialist III
Partner - Specialist III

How about putting Cost as negative on the chart with

Sum (CostValue * -1)

Would this be acceptable?

Not applicable
Author

it works...but it's really bad 😛

other solution ?

Not applicable
Author

it works...but it's really bad 😛

other solution ?

disqr_rm
Partner - Specialist III
Partner - Specialist III

Not that I know of. May be messing around with macros would do the trick, but nothing firm I can think of.

At least you have one option now (better then nothing). 😉

johnw
Champion III
Champion III

Attached is one approach. Instead of using a grouped expression, I create a grouped dimension, then use getcurrentfield() to figure out which "expression" is selected, and calculate it and sort it appropriately. I'm hoping that some future version of QlikView lets us name expression groups and use a similar function to figure out which expression is selected. Or perhaps it already does, and I just don't know about it yet.

disqr_rm
Partner - Specialist III
Partner - Specialist III

Wow!!! Excellent John. Thanks.

Not applicable
Author

wonderful...it works!

thanks a lot :))

Not applicable
Author

Thanks for sharing. I like the idea.

Any idea if there is an impact on performance with the use of an 'if' statement in the sort?

johnw
Champion III
Champion III


Tyler Waterfall wrote:Any idea if there is an impact on performance with the use of an 'if' statement in the sort?


I haven't done any testing, but I would expect the performance impact to be negligible. Generally speaking, when the IF is outside of the aggregation, it should be evaluated once, and therefore not impact performance. When the IF is inside of the aggregation, it needs to be evaluated multiple times, and can therefore cause performance problems with large data sets. This one is outside of the aggregation, so should be fine in theory.

Edit: Slight misstatement, perhaps. The IF is INSIDE of the aggregation by the dimensions of the chart. What I meant is that it isn't inside of the sum(). I'm not doing a sum(if()). Being evaluated once for each row of a chart isn't typically a problem, but perhaps could be in very large straight tables or pivot tables.