Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Sort and group in script

Dear Qlik community,

Advise me pls on the question - I need to group Net_Sales in script by Customer, than sort by Net_Sales with descending.

What I'm trying to perform:

LOAD Cust as Customer,

     sum([Sales net]) as Net_Sales

Resident SalesTable

Group by Cust

Order By [Sales net] desc;

Thanks

1 Solution

Accepted Solutions
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

As far as I understand (and I might be wrong about it), you can't group and sort by a new calculated field in the same statement. Here is what's stated in QlikView Help:

================================

order by is a clause used for sorting the records of a resident table before they are processed by the load statement. The resident table can be sorted by one or more fields in ascending or descending order. The sorting is made primarily by numeric value and secondarily by national ASCII value. This clause may only be used when the data source is a resident table

================================

Based on that, you should first group your data, and then reload the same table again in a resident load and sort it using the ORDER BY clause.

cheers,

Oleg Troyansky

Upgrade your Qlik skills at the Masters Summit for Qlik - coming soon to Milan, Italy and Austin, TX!

View solution in original post

3 Replies
swuehl
MVP
MVP

The order by clause is sorting the input records, not the output records.

[From the HELP:

order_by   order by  is a clause used for sorting the records of a resident table before they are processed by the load statement

]

so you would need a subsequent LOAD to order your aggregated values as demanded.

Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

As far as I understand (and I might be wrong about it), you can't group and sort by a new calculated field in the same statement. Here is what's stated in QlikView Help:

================================

order by is a clause used for sorting the records of a resident table before they are processed by the load statement. The resident table can be sorted by one or more fields in ascending or descending order. The sorting is made primarily by numeric value and secondarily by national ASCII value. This clause may only be used when the data source is a resident table

================================

Based on that, you should first group your data, and then reload the same table again in a resident load and sort it using the ORDER BY clause.

cheers,

Oleg Troyansky

Upgrade your Qlik skills at the Masters Summit for Qlik - coming soon to Milan, Italy and Austin, TX!