Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
ecabanas
Creator II
Creator II

How to do an order counter id

Hi guys

I have a table with the CUSTACCOUNT, SALESID and CREATEDDATETIME. In the master table obviously I have several CUTACCOUNT and SALESID, but I would like to "numerate" the orders, in order to know Frequency, etc etc. as in the following table

Many many thanks

Eduard

CUSTACCOUNTSALESIDCREATEDDATETIMEOrder Number
C000002PV0016141216/09/20111
C000002PV0016144719/09/20112
C000002PV0016145920/09/20113
C000002PV9000011517/10/20114
C000002PV0016277328/12/20115
C000002PV9000025128/12/20116
C000002PV0016361510/02/20127
C000002PV0016742602/08/20128
C000002PV0016783317/08/20129
C000002PV0017214826/10/201210
C000002PV0017505812/12/201211
C000002PV0017567222/12/201212
C000002PV0017630504/01/201313
C000002PV0017776625/01/201314
C000002PV0017923815/02/201315
C000002PV0018106313/03/201316
C000002PV0018209801/04/201317
C000002PV0018334519/04/201318
C000002PV0018495813/05/201319
C000002PV0018626930/05/201320
C000002PV0018962804/07/201321
C000002PV0019265313/08/201322
C000002PV0019578116/09/201323
1 Solution

Accepted Solutions
sunny_talwar

Slight change in the script:

Table:

LOAD CUSTACCOUNT,

    SALESID,

    CREATEDDATETIME

FROM

[https://community.qlik.com/thread/186667]

(html, codepage is 1252, embedded labels, table is @2);

FinalTable:

LOAD *,

  RowNo() as [Order Number]

Resident Table

Order By CUSTACCOUNT, CREATEDDATETIME;

DROP Table Table;

Output in Table Box:

Capture.PNG

View solution in original post

11 Replies
sunny_talwar

May be something like this:

LOAD CUSTACCOUNT,

          SALESID,

          CREATEDDATETIME,

          RowNo() as [Order Number]

FROM Source

nagaiank
Specialist III
Specialist III

You may use RowNo() as OrderNumber.

E.g LOAD RowNo() as OrderNumber,

      CUSTACCOUNT,

      SALESID,

      CREATEDATETIME

From (Your Source)

ecabanas
Creator II
Creator II
Author

Hi Sunny,

The problem is that the source table is not ordered is like this:

CUSTACCOUNTSALESIDCREATEDDATETIME
C000015PV0016113303/09/2011
C000002PV0016141216/09/2011
C000002PV0016144719/09/2011
C000002PV0016145920/09/2011
C000014PV0016158429/09/2011
C000003PV0016173111/10/2011
C000015PV0016180915/10/2011
C000002PV9000011517/10/2011
C000003PV0016195727/10/2011
C000015PV0016215710/11/2011
C000003PV0016225918/11/2011
C000014PV0016226018/11/2011
C000014PV0016227320/11/2011
C000003PV9000020313/12/2011
C000002PV0016277328/12/2011
C000002PV9000025128/12/2011
C000014PV0016329722/01/2012
C000002PV0016361510/02/2012
C000015PV0016395326/02/2012
C000005PV0016433222/03/2012
C000015PV0016445727/03/2012
C000014PV0016454201/04/2012
C000015PV0016499501/05/2012
C000014PV0016519811/05/2012
C000014PV0016534117/05/2012
sunny_talwar

Try this:

Table:

LOAD CUSTACCOUNT,

    SALESID,

    CREATEDDATETIME

FROM

[https://community.qlik.com/thread/186667]

(html, codepage is 1252, embedded labels, table is @2);

FinalTable:

LOAD *,

  RowNo() as [Order Number]

Resident Table

Order By CUSTACCOUNT, SALESID;

DROP Table Table;



maxgro
MVP
MVP

A different one:

you can use (in a chart) a count of a not null field in the same table to know the number of rows.

1.png

sunny_talwar

Slight change in the script:

Table:

LOAD CUSTACCOUNT,

    SALESID,

    CREATEDDATETIME

FROM

[https://community.qlik.com/thread/186667]

(html, codepage is 1252, embedded labels, table is @2);

FinalTable:

LOAD *,

  RowNo() as [Order Number]

Resident Table

Order By CUSTACCOUNT, CREATEDDATETIME;

DROP Table Table;

Output in Table Box:

Capture.PNG

ecabanas
Creator II
Creator II
Author

Hi Sunny,

Where are going by the good track, but I want to know the counter per customer. For example in your table, when it changes from custaccount  C00002 to C00003 the counter has to be reseted....I want to know the order number by customer

Many many thanks guys!!

Eduard

maxgro
MVP
MVP

x:

load *

inline [

CUSTACCOUNT, SALESID, CREATEDDATETIME

C000015, PV00161133, 03/09/2011

C000002, PV00161412, 16/09/2011

C000002, PV00161447, 19/09/2011

C000002, PV00161459, 20/09/2011

C000015, PV00164457, 27/03/2012

C000014, PV00164542, 01/04/2012

C000015, PV00164995, 01/05/2012

C000014, PV00165198, 11/05/2012

C000014, PV00161584, 29/09/2011

C000003, PV00161731, 11/10/2011

C000015, PV00161809, 15/10/2011

C000002, PV90000115, 17/10/2011

C000003, PV00161957, 27/10/2011

C000015, PV00162157, 10/11/2011

C000003, PV00162259, 18/11/2011

C000014, PV00162260, 18/11/2011

C000014, PV00162273, 20/11/2011

C000003, PV90000203, 13/12/2011

C000002, PV00162773, 28/12/2011

C000002, PV90000251, 28/12/2011

C000014, PV00163297, 22/01/2012

C000002, PV00163615, 10/02/2012

C000015, PV00163953, 26/02/2012

C000005, PV00164332, 22/03/2012

C000014, PV00165341, 17/05/2012

] ;

y:

NoConcatenate load *, AutoNumber(rowno(), CUSTACCOUNT) as id Resident x

order by  CUSTACCOUNT, CREATEDDATETIME;

DROP Table x;

sunny_talwar

May be this:

Table:

LOAD CUSTACCOUNT,

    SALESID,

    CREATEDDATETIME

FROM

[https://community.qlik.com/thread/186667]

(html, codepage is 1252, embedded labels, table is @2);

FinalTable:

LOAD *,

  If(Peek('CUSTACCOUNT') = CUSTACCOUNT, Peek('Order Number') + 1, 1) as [Order Number]

Resident Table

Order By CUSTACCOUNT, CREATEDDATETIME;

DROP Table Table;


Capture.PNG