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 records while loading

My question is like this.

below is my original data

    type, action, date, customer

    Repair, Re001, 33, customer001

    Install, In001, 30, customer001

    Repair, Re002, 43, customer001   

    Install, In002, 30, customer002

    Repair, Re002, 39, customer002

I just want to load them all and have another "sort order" field and my result should be like this below. I mean group by customer and order by date.

     

typeactioncustomersort orderdate
InstallIn001customer001130
RepairRe001customer001233
RepairRe002customer001343
InstallIn002customer002130
RepairRe002customer002239

how can I write the script.

1 Solution

Accepted Solutions
sunny_talwar

Try this:

Table:

LOAD * Inline [

type, action, date, customer

    Repair, Re001, 33, customer001

    Install, In001, 30, customer001

    Repair, Re002, 43, customer001 

    Install, In002, 30, customer002

    Repair, Re002, 39, customer002

];

FinalTable:

LOAD *,

  AutoNumber(RecNo(), customer) as [sort order]

Resident Table

Order By customer, date;

DROP Table Table;


Capture.PNG

View solution in original post

6 Replies
danansell42
Creator III
Creator III

Hi

Have you tried the following?

Load

     Type,

     Action,

     Date,

     Customer,

     RecNo() as SortOrder

from Table...

Order by Customer, Date asc;

Thanks

Dan

sunny_talwar

Try this:

Table:

LOAD * Inline [

type, action, date, customer

    Repair, Re001, 33, customer001

    Install, In001, 30, customer001

    Repair, Re002, 43, customer001 

    Install, In002, 30, customer002

    Repair, Re002, 39, customer002

];

FinalTable:

LOAD *,

  AutoNumber(RecNo(), customer) as [sort order]

Resident Table

Order By customer, date;

DROP Table Table;


Capture.PNG

squeakie_pig
Creator II
Creator II

Can only do an order by on a Resident Load.

danansell42
Creator III
Creator III

Apologies, Yes you are correct.

In my test i did do a resident load however when i typed it here for some reason i removed that element for ease of reading which was obviously not the best thing to do 😕

Temp:

LOAD * INLINE [

    Type, Action, Date, Customer

    Repair,  Re001, 33,  customer001

    Install,  In001, 30,  customer001

    Repair,  Re002, 43,  customer001  

    Install,  In002, 30,  customer002

    Repair,  Re002, 39,  customer002

];

Test:

Load *,

  RecNo() as SortOrder

resident Temp

Order by Customer, Date asc;

drop Table Temp;

Not applicable
Author

it's not working.  the result will be

           

wotypeactioncustomerdateSortOrder   I want
InstallIn001customer0013011
RepairRe001customer0013322
RepairRe002customer0014333
InstallIn002customer0023041
RepairRe002customer0023952

Not applicable
Author

I actually tried this way. quite the same as your answer. thank you.

tmp:

LOAD * INLINE [

    wotype, action, date, customer

    Repair, Re001, 33, customer001

    Install, In001, 30, customer001

    Repair, Re002, 43, customer001   

    Install, In002, 30, customer002

    Repair, Re002, 39, customer002

];

NoConcatenate

tmp_1:

load AutoNumber(date,customer),customer,date,action,wotype

Resident tmp

order by customer,date;