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

Number os sales accumulated

Hi guys again,

I want to know the number of the sales of a table.

I have this code to know the frequency, but I also want to know wich sale number is, For example "The third o the second"

Result:

LOAD

     SALESID,

     CUSTACCOUNT,

     CREATEDDATETIME,

If(CUSTACCOUNT=Previous(CUSTACCOUNT), CREATEDDATETIME-Previous(CREATEDDATETIME)) as "Frequency",

Count(DISTINCT SALESID) AS "nUMBER"

Resident SALESTABLEPRE

Order By SALESID, CUSTACCOUNT, CREATEDDATETIME;

But did not work 😞

Many thanks

Eduard

1 Solution

Accepted Solutions
swuehl
MVP
MVP

I would sort the input table first by Customer, then by SalesId or Date. You can use AutoNumber to count the Sales order per Customer:

Result:

LOAD

     SALESID,

     CUSTACCOUNT,

     CREATEDDATETIME,

If(CUSTACCOUNT=Previous(CUSTACCOUNT), CREATEDDATETIME-Previous(CREATEDDATETIME)) as "Frequency",

Autonumber(SALESID, CUSTACCOUNT)  AS [#SALES]

Resident SALESTABLEPRE

Order By CUSTACCOUNT, SALESID;

View solution in original post

7 Replies
swuehl
MVP
MVP

A Count() in your LOAD statement requires a GROUP BY clause.

I am unsure what you want to achieve, could you upload a few lines of sample data and your requested result?

ecabanas
Creator II
Creator II
Author

Hi,

My table has SalesId, Customer and date.

I wanna know is, the number of days from one order to another and what order number is (the second, the third, etc)

I wanna answer this question: How many days take our customers from 2nd to 3rd order?

 

SalesIdCustomerDateFrequency#SALES
PV0001C000101/01/2015 1
PV0002C000201/01/2015 1
PV0003C000301/01/2015 1
PV0004C000101/02/2015312
PV0005C000210/02/2015402
PV0006C000315/02/2015452
PV0007C000101/03/2015283
PV0008C000214/03/2015323
PV0009C000318/03/2015313
swuehl
MVP
MVP

I would sort the input table first by Customer, then by SalesId or Date. You can use AutoNumber to count the Sales order per Customer:

Result:

LOAD

     SALESID,

     CUSTACCOUNT,

     CREATEDDATETIME,

If(CUSTACCOUNT=Previous(CUSTACCOUNT), CREATEDDATETIME-Previous(CREATEDDATETIME)) as "Frequency",

Autonumber(SALESID, CUSTACCOUNT)  AS [#SALES]

Resident SALESTABLEPRE

Order By CUSTACCOUNT, SALESID;

Digvijay_Singh

This also works but I think Stefan's one is better one -

temp:

Load * Inline [

SalesId Customer Date

PV0001 C0001 01/01/2015

PV0002 C0002 01/01/2015

PV0003 C0003 01/01/2015

PV0004 C0001 01/02/2015

PV0005 C0002 10/02/2015

PV0006 C0003 15/02/2015

PV0007 C0001 01/03/2015

PV0008 C0002 14/03/2015

PV0009 C0003 18/03/2015

] (delimiter is '');

Output:

Load *,if(Customer=previous(Customer),Date(Date#(Date,'DD/MM/YYYY'))-Date(Date#(Peek('Date',-1),'DD/MM/YYYY'))) as Frequency,

  if(Customer<>previous(Customer),1,alt(peek('SaleNBR',-1),0)+1) as SaleNBR

Resident temp Order By Customer,SalesId;

Drop table temp;

ecabanas
Creator II
Creator II
Author

WOWWWW again!!! many many thank's

if you come to Barcelona a paella is waiting you 😉

Regards

Eduard

ecabanas
Creator II
Creator II
Author

Hi Swuehl

Checking the result the Frequency calculation is not correct, did you know why?

Many thank's

SALESID#SALESDAYFREQCREATEDDATETIMECUSTACCOUNT
PR10243479PR10243479PR1024347902/11/2014C111507
PV90004533PV90004533PV9000453304/11/2014C111507
PV00225593131/05/2014C111507
PV0023325221049804/08/2014C111507
PV002361673643529/08/2014C111507
PV00239092445022/09/2014C111507
PV002415385-62711/10/2014C111507
PV002434796137929/10/2014C111507
PV002455657515217/11/2014C111507
PV002495658129120/12/2014C111507
PV002513579171310/01/2015C111507
PV0025478210685807/02/2015C111507
PV0025919411115915/03/2015C111507
PV00278699121773219/08/2015C111507
swuehl
MVP
MVP

Could you post your script code you have used to create the ouput?