Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
sharu055
Contributor III
Contributor III

How to do primary and secondary sort in Straight table

I have 3 columns in straight table. Team, Date, Result. Need the Sorting that Result column as primary sort that only only Won, Lost should appear as first and Tie, No  Result should come second and Date column should be as secondary sort  where  old dates should comes at first as ascending.  below are my input n needed output. please help

Input:

Team Date Result
IND 5/25/2022 Lost
CHI 5/15/2022 Tie
UK 4/22/2022 Lost
IND 4/31/2022 Won
UK 5/3/2022 No Result
USA 4/30/2022 Tie
CHI 5/31/2022 Won
USA 6/1/2022 No Result
UK 6/30/2022 Lost

 

After Sort Output need as below :

Team Date Result
UK 4/22/2022 Lost
IND 4/31/2022 Won
IND 5/25/2022 Lost
CHI 5/31/2022 Won
UK 6/30/2022 Lost
USA 4/30/2022 Tie
UK 5/3/2022 No Result
CHI 5/15/2022 Tie
USA 6/1/2022 No Result

 

Please help.

3 Replies
31520Samuel
Contributor II
Contributor II

Looking for the same issue. Bumped into your thread. Thanks for creating it. Looking forward for solution. CredibleBH Employee Login

edwin
Master II
Master II

you would normally use a sort by expression.  most that i have seen have sort weight associated to individual values (Won before lost, etc..).  however, yours is sorted by a grouping of values and i noticed that Qlik Sense sorts the group and then sorts the individual Values.  so the order becomes Lost, Lost, Lost, Won, Won,...

the result order is correct but the date order was amiss.  what i had to do was bias the date as well:

edwin_0-1679509225554.png

notice I ordered it by date first so as to overcome the sorting by values of Result, then i added this as the sort expression for Date:

=if(Result='Lost' or Result='Won',1,2)*10000000 + num(Date)

i didnt even need to sort by Result as that was baked into the sort expression for Date.
you can of course play around with the same idea until you get to an acceptable solution

edwin
Master II
Master II

follow on, i did this obviously in QLik sense