Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
robmarr789
Contributor
Contributor

sort dates in script

I have an expression which enables me to calculate 12 month rolling totals. However for it to work I need to pre sort my dates in ascending  order. Can anyone add some script to the attached that will do this for me?

1 Solution

Accepted Solutions
sunny_talwar

Check out the following script

Table:

LOAD * INLINE [

    CustomerGroupName, Date, Sales, Year

    A, 01/01/2018, 37610.56, 2018

    B, 01/02/2018, 32214.18, 2018

    C, 01/03/2018, 24255.54, 2018

    D, 01/04/2018, 23568.69, 2018

    E, 01/05/2018, 22122.75, 2018

    F, 01/06/2018, 18583.91, 2018

    G, 01/07/2018, 14729.65, 2018

    H, 01/08/2018, 14533.58, 2018

    I, 01/09/2018, 14075.58, 2018

    J, 01/10/2018, 11186.97, 2018

    k, 01/11/2018, 10854.74, 2018

    L, 01/12/2018, 10286.59, 2018

    M, 01/01/2018, 9866.57, 2018

    N, 01/02/2018, 9820.89, 2018

    O, 01/03/2018, 9462.79, 2018

    P, 01/04/2018, 8188.33, 2018

    Q, 01/05/2018, 7860.28, 2018

    A, 01/06/2017, 38221.12, 2017

    B, 01/07/2017, 33428.36, 2017

    C, 01/08/2017, 22955.53, 2017

    D, 01/09/2017, 23567.69, 2017

    E, 01/10/2017, 14245.5, 2017

    F, 01/11/2017, 12167.82, 2017

    G, 01/12/2017, 19459.3, 2017

    H, 01/01/2017, 17067.16, 2017

    I, 01/02/2017, 13151.16, 2017

    J, 01/03/2017, 12373.94, 2017

    k, 01/04/2017, 11709.48, 2017

    L, 01/05/2017, 573.18, 2017

    M, 01/06/2017, 9733.14, 2017

    N, 01/07/2017, 11641.78, 2017

    O, 01/08/2017, 11925.58, 2017

    P, 01/09/2017, 8876.66, 2017

    Q, 01/10/2017, 5720.56, 2017

];


FinalTable:

LOAD *,

Month(Date) as Month,

MonthName(Date) as MonthYear

Resident Table

Order By Date;


DROP Table Table;

View solution in original post

2 Replies
jduenyas
Specialist
Specialist

In the tab <Sort> of the table Sales (not the chart, it seems that the chart is OK) and in the Box Priority select Month and promote it. That will have your table sorted by Month first and then by Sales.

Is that what you are asking for?

sunny_talwar

Check out the following script

Table:

LOAD * INLINE [

    CustomerGroupName, Date, Sales, Year

    A, 01/01/2018, 37610.56, 2018

    B, 01/02/2018, 32214.18, 2018

    C, 01/03/2018, 24255.54, 2018

    D, 01/04/2018, 23568.69, 2018

    E, 01/05/2018, 22122.75, 2018

    F, 01/06/2018, 18583.91, 2018

    G, 01/07/2018, 14729.65, 2018

    H, 01/08/2018, 14533.58, 2018

    I, 01/09/2018, 14075.58, 2018

    J, 01/10/2018, 11186.97, 2018

    k, 01/11/2018, 10854.74, 2018

    L, 01/12/2018, 10286.59, 2018

    M, 01/01/2018, 9866.57, 2018

    N, 01/02/2018, 9820.89, 2018

    O, 01/03/2018, 9462.79, 2018

    P, 01/04/2018, 8188.33, 2018

    Q, 01/05/2018, 7860.28, 2018

    A, 01/06/2017, 38221.12, 2017

    B, 01/07/2017, 33428.36, 2017

    C, 01/08/2017, 22955.53, 2017

    D, 01/09/2017, 23567.69, 2017

    E, 01/10/2017, 14245.5, 2017

    F, 01/11/2017, 12167.82, 2017

    G, 01/12/2017, 19459.3, 2017

    H, 01/01/2017, 17067.16, 2017

    I, 01/02/2017, 13151.16, 2017

    J, 01/03/2017, 12373.94, 2017

    k, 01/04/2017, 11709.48, 2017

    L, 01/05/2017, 573.18, 2017

    M, 01/06/2017, 9733.14, 2017

    N, 01/07/2017, 11641.78, 2017

    O, 01/08/2017, 11925.58, 2017

    P, 01/09/2017, 8876.66, 2017

    Q, 01/10/2017, 5720.56, 2017

];


FinalTable:

LOAD *,

Month(Date) as Month,

MonthName(Date) as MonthYear

Resident Table

Order By Date;


DROP Table Table;