Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Not applicable

Qlik Sense - Order by in load script

Hi experts!

Is it possible to order a table in the LOAD SCRIPT by a specific field in Qlik Sense?

I have to do that in the load script, because i want to add another filed with sequential numbers there.

Thank you!

12 Replies
ahaahaaha
Honored Contributor

Re: Qlik Sense - Order by in load script

Hi Andrea,

The main thing - Order By works only for already loaded tables.

For example,

LOAD

....,

MyField

Resident MyTable

Order By MyField;

Regards,

Andrey

omarbensalem
Esteemed Contributor

Re: Qlik Sense - Order by in load script

Yes, sure !

It would be sthing like this:

Load

A,

B,

C

from yourTable

ORDER BY A;

Not applicable

Re: Qlik Sense - Order by in load script

Thank you for your reply!

let's say i have something like this:

LOAD

A,

B,

C;

SQL SELECT A,

B,

C

FROM .....

I would like to order the table by the field "A", and only when ordered add the rowno() in the load script. Could you please provide me an example of code?

Thank you

Not applicable

Re: Qlik Sense - Order by in load script

Thank you for your reply!

let's say i have something like this:

LOAD

A,

B,

C;

SQL SELECT A,

B,

C

FROM .....

I would like to order the table by the field "A", and only when ordered add the rowno() in the load script. Could you please provide me an example of code?

Thank you

omarbensalem
Esteemed Contributor

Re: Qlik Sense - Order by in load script

load *, rowNo() as RowNo;

LOAD

A,

B,

Order By A;

SQL SELECT A,

B,

C

FROM .....

Not applicable

Re: Qlik Sense - Order by in load script

Thank you again Omar! I've not been that clear sorry

the code does not work, it displayed the error: field " " not found.

the fact is taht i would like to order the entire table by a Date Filed (recent first), then assign a rowno() to the table (lower number --> more recent dates).

Please help me! Thank you!

omarbensalem
Esteemed Contributor

Re: Qlik Sense - Order by in load script

Can you paste your code and an image of the shown error?

Not applicable

Re: Qlik Sense - Order by in load script

this is the code:

LIB CONNECT TO 'XXX';

load *, rowNo() as RowNo;

LOAD id,

    oKey,

    pId as PID,

    RDate,

    RDate&': '&oKey&id&pId as IDconcat,

    order by IDconcat

    ;

SQL SELECT id,

    oKey,

    pId,

    RDate

FROM "XXX_xxx".dbo."XXXABC"

WHERE YEAR(RDATE)>YEAR(GETDATE())-3

;

this is the error:

sssss.PNG

the fact is that i want to first order the table by the IDconcat, then add rowno().

Thankyou!!

ahaahaaha
Honored Contributor

Re: Qlik Sense - Order by in load script

Hi Andrea,

As variant,

Table1:

LOAD

A,

B,

C

FROM....;

NoConcatenate

Table2:

LOAD*

Resident Table1

Order By A;

DROP Table Table1;

I'll note again, Order By works only with resident (internal) tables. Sort immediately during download from the database SQL will not work.

Regards,

Andrey