Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

sort in script

Hi,

I would like to create a cumulative values of [Adunt Impacts] using the following script:

RangeSum([Adult Impacts],Peek('Cumulative_AdsImpact')) as Cumulative_AdsImpact

However to make sense of it my date need to be sorted by DateTime field before cumulation.

How can I sort my data in script?

Any ideas pleae?

Thanks

1 Solution

Accepted Solutions
Gysbert_Wassenaar

Like this:

ConsData:

Load

     Date,

     [Adult Impacts],

     ....

ResultData:

NoConcatenate LOAD

      Date,

     [Adult Impacts],

     RangeSum([Adult Impacts],Peek([Cumulative Adult Impacts])) as [Cumulative Adult Impacts],

     ...

Resident ConsData Order By Date;

Drop table ConsData; // ConsData is no longer needed, all the data is now in table ResultData


talk is cheap, supply exceeds demand

View solution in original post

6 Replies
nagaiank
Specialist III
Specialist III

Use the following example script

Data:

LOAD * Inline [

Date, Adult Impacts

1/2/2013,10

1/4/2013,20

1/3/2013,25

1/1/2013,5

];

Result:

NoConcatenate LOAD Date, [Adult Impacts]

,RangeSum([Adult Impacts],Peek([Cumulative Adult Impacts])) as [Cumulative Adult Impacts]

Resident Data Order By Date;

Sample application is attached.

Not applicable
Author

Does it mean I have to manually write all Dates and Impacts?

nagaiank
Specialist III
Specialist III

No. If you have your data in a table named 'Data', you may use it in the second load.

For the sample application to illustrate the script, I loaded data as Inline load.

Not applicable
Author

I have this table ConsData with data loaded already:

ConsData:

Load

     Date,

     [Adult Impacts],

     ...

So below that I need to type your code?

NoConcatenate LOAD Date, [Adult Impacts]

,RangeSum([Adult Impacts],Peek([Cumulative Adult Impacts])) as [Cumulative Adult Impacts]

Resident Data Order By Date;

Sorry but I am quiet new to it.

Gysbert_Wassenaar

Like this:

ConsData:

Load

     Date,

     [Adult Impacts],

     ....

ResultData:

NoConcatenate LOAD

      Date,

     [Adult Impacts],

     RangeSum([Adult Impacts],Peek([Cumulative Adult Impacts])) as [Cumulative Adult Impacts],

     ...

Resident ConsData Order By Date;

Drop table ConsData; // ConsData is no longer needed, all the data is now in table ResultData


talk is cheap, supply exceeds demand
Not applicable
Author

Thanks Gysbert for detailed explenation. It was really helpful to get the idea.