Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
kaygee28
Contributor III
Contributor III

Calculating Customer Purchasing Cycle

Hi All

I'm stuck with a predicament, I was wondering how I would calculate a customers purchasing cycle and get a graph like this below if possible. However this time around I would get the different vehicle desciptions in the x-axis.

Repurchases Graph.png

my data might be a problem at the moment since the repurchasing period needs to be calculated for each model and then the average of the purchasing cycle is calculated thereafter.


here is a sample of my data below:

  

Business PartnerBP: First NameBP: SurnameVehicle VersionVehicle SeriesVehicle ModelDescriptionCalendar daySales
10001696Svan WykE3277 SERIESGA48730i Sedan05/01/19881
10001696Svan WykE3277 SERIESGA48730i Sedan31/08/19901
10001696Svan WykE3277 SERIESGA48730i Sedan17/09/19911
10002228Ronald CharlesRussellE3277 SERIESGB68735i Sedan24/08/19921
10002302RIDWANJASATE6577 SERIESHL02760i Sedan30/12/20091
10002302RIDWANJASATE6577 SERIESHL62740i Sedan29/09/20061
10002370Brendan JohnTraillE3277 SERIESGA48730i Sedan01/08/19961

I hope this makes sense.

Thanks in advance.

8 Replies
kaygee28
Contributor III
Contributor III
Author

Oh Okay, I think I found a way but I need to find a way to make the calendar dates subtract from each other using the peek function. From then on I will create a chart with the description field as my dimension and I'll then average the newly crated [Repurchases] field. here is my code below:

Main:

LOAD [Business Partner],

     [BP: First Name],

     [BP: Surname],

     [Vehicle Version],

     [Vehicle Series],

     F6,

     [Vehicle Model],

     Description,

     date(date#([Calendar day],'dd/mm/yyyy')) as  [Calendar day],

     Sales

    

         

FROM

[BMW Repurchases.xlsx]

(ooxml, embedded labels, table is [BMW (65)]);

Find_Duplicates:

NoConcatenate

load *,

If([Business Partner] = Peek('[Business Partner]', -1),[Calendar day] - Peek('[Calendar day]', -1),0) as [Repurchases]

resident Main;

drop table Main;

Thanks in advance!

sunny_talwar

Would you be able to share what you have right now and what are you trying to get to?

kaygee28
Contributor III
Contributor III
Author

Hi Sunny

Not sure my last message was delivered but what Im trying to saty is that the peek function isn't picking up the date field which is the [Calendar day] field hence the calculations aren't being done properly.

For instance if Sunny has bought multiple cars in say 2010 and 2011 then the difference should be 1 year hence thats what I am trying to do with the peek function for each [Business Partner] field.

Please see attached app.

Ultimately I want to get a graph as shown below, with the Description field as my dimension and the repurchases field as my calculation index.

Repurchases Graph.png

sunny_talwar

I think try this code....

Main:

LOAD [Business Partner],

    [BP: First Name],

    [BP: Surname],

    [Vehicle Version],

    [Vehicle Series],

    F6,

    [Vehicle Model],

    Description,

    Date(Date#([Calendar day], 'DD/MM/YYYY')) as [Calendar day],

    Sales

FROM

[BMW Repurchases.xlsx]

(ooxml, embedded labels, table is [BMW (65)]);

Find_Duplicates:

NoConcatenate

LOAD *,

If([Business Partner] = Peek('Business Partner'), [Calendar day] - Peek('Calendar day'), 0) as [Repurchases]

Resident Main

Order By [Business Partner];

DROP Table Main;

sunny_talwar

Not 100% sure, but you might need a sort on the Calendar day field as well:

Main:

LOAD [Business Partner],

    [BP: First Name],

    [BP: Surname],

    [Vehicle Version],

    [Vehicle Series],

    F6,

    [Vehicle Model],

    Description,

    Date(Date#([Calendar day], 'DD/MM/YYYY')) as [Calendar day],

    Sales

FROM

[BMW Repurchases.xlsx]

(ooxml, embedded labels, table is [BMW (65)]);

Find_Duplicates:

NoConcatenate

LOAD *,

If([Business Partner] = Peek('Business Partner'), [Calendar day] - Peek('Calendar day'), 0) as [Repurchases]

Resident Main

Order By [Business Partner], [Calendar day];

DROP Table Main;

kaygee28
Contributor III
Contributor III
Author

Hi Sunny

I see but this doesn't aggregate for each unique [business partner] field, this does the calculation for all the business partners irrelevant of the ID, and furthermore the calculation is in integer format such as 4996 whereas I want it as 4.6 years for instance.

sunny_talwar

You can do the aggregation on the front end using Sum() function. How is 4996 = 4.6 years?

kaygee28
Contributor III
Contributor III
Author

From my understanding a date is interpreted as a numeric in qlikview hence I was just making a generic reference  it wasn't even accurate, thanks Sunny!