Forum Discussion
Customer Repurchase Cycle
- 4 years ago
Anonymous Hi, considering your issues I made measures as below. I hope this helps you.
//[NumOfTotPurchase]: This counts all purchases even if order numbers are the same. e.g. if Emil purchased 4 macbooks on the same day under same oerder number, it still counts 4.
NumOfTotPurchase = countrows(All_Platforms)//[NumOfVisit]: This counts only number of visit regardless number of purchases e.g. If Emil purchased 4 macbooks, if counts only 1 as long as all purchases are done under same order numberNumOfVisit =VAR currentuser = MAX( All_Platforms[User Name] )VAR NumOfVisit =COUNTROWS(DISTINCT(SELECTCOLUMNS(FILTER( All_Platforms, All_Platforms[User Name] = currentuser ),"OrderNum", All_Platforms[Order Number],"Name", All_Platforms[User Name])))Return NumOfVisit//[NumOfReVisit]: This is the same as above [NumOfVisit] but it excludes the first visit. hence the formular is simply [NumOfVisit]-1NumOfReVisit = [NumOfVisit]-1//[AVG_Time_Revisit_Indv]: This is similar to the measure [AverageTime_Revisit] which I provided previously but it is revised to ignore bulk purchase under the same order number. But this measure cannot be used universal purpose(e.g. KPI card) since it needs specific "Name". Just make this measure in your model but don't use this. this measure will be used internally to make the final new measureAVG_Time_Revisit_Indv =VAR currentuser = MAX( All_Platforms[User Name] )VAR NumberOfDates =CALCULATE(DATEDIFF(FIRSTNONBLANK( All_Platforms[OrderTime], All_Platforms[OrderTime] ),LASTNONBLANK( All_Platforms[OrderTime], All_Platforms[OrderTime] ),DAY),All_Platforms[User Name] = currentuser)VAR NumberOfRePurcases =COUNTROWS(DISTINCT(SELECTCOLUMNS(FILTER( All_Platforms, All_Platforms[User Name] = currentuser ),"OrderNum", All_Platforms[Order Number],"Name", All_Platforms[User Name]))) - 1VAR Avg_Time_Interval =CALCULATE(DIVIDE( NumberOfDates, NumberOfRePurcases ),ALLSELECTED( all_Platforms ))Return Avg_Time_Interval//[Avg_Revisit_Interval]: This is the one you can use to show revisit interval for individual as well as overall time interval (for KPI card)Avg_Revisit_Interval =AVERAGEX(ADDCOLUMNS(VALUES( All_Platforms[User Name] ),"AvgTime", [AVG_Time_Revisit_Indv] ),[AVG_Time_Revisit_Indv])//[Time_till_next_visit ]: This is the measure you can use along with speciifc date which shows the number of dates till next visit. e.g. if you select the date when Emil visited, this measure will show the number of dates till Emil's next visitTime_till_next_visit =VAR current_date = max(All_Platforms[OrderTime])VAR Next_visit =CALCULATE(min(All_Platforms[OrderTime]),All_Platforms[OrderTime] > current_date)RETURN DATEDIFF(current_date,Next_visit,DAY)//[Avg_Revist_Time_From]: This is similar to above [Time_till_next_visit ] which you can use along with speciifc date. While [Time_till_next_visit ] shows the number of dates till next visit, this measure show average number of dates for revisit calculating till last visit date. You need to create the measure [NumOfVisit] first to create this measureAvg_Revist_Time_From =VAR current_date = max(All_Platforms[OrderTime])VAR Fianl_visit =CALCULATE(MAX(All_Platforms[OrderTime]),All_Platforms[OrderTime] > current_date)VAR DateDifference = DATEDIFF(current_date,Fianl_visit,DAY)VAR Num_visit =CALCULATE([NumOfVisit],All_Platforms[OrderTime] > current_date)RETURN DIVIDE( DateDifference,Num_visit)Please mark this as solution if this helped you.
Anonymous Hi, Jannnn04,
Q2-1 : Pllease double check the formular
it's NumberOfPurchase = countrows(All_Platforms) not countrows(All(All_Platforms))
In above table table, the value should be 1 for each row not 138.
Let me explain a bit here why the number should be 1 and this explanation is also realted to the answer to your Q2-2.
In above table, you have added all the columns, which means you have added all the conditions to get the number of Purchase under all these conditions.
Your question to power BI for the first row is:
"Show me how many items Emil bought Latop which is macbook on 3rd March 2021". of cuase the answer would be 1 because your question is too specific.
However if you change the question with less conditions by removing some columns,
""Show me how many items Emil bought Latop" then the answer would be 2 as below
The answer to Q2-2 will be the same. since you have put all the conditions in the table above, there are only unique and very specific cases. and there is no way to calculate time diffrence for 1 case. (at least 2 purchases are quired to calculate time difference)
but if you reduce conditions (reduce columns of the table), like
"How frequently Emil buy item?" ==> total 4 times and on average 24.3 days took for each purchase
OR "how frequently Emil bought macbook" ==> 14 days, and so on.
I hope it clariied your concern.
Thanks
Good Morning Colacan!
thanks again for your help 🙂
Q2-1: I think I have found the core of the problem. I was creating columns instead of measures before (why is that so?). Now that I used measures with the formulars that you kindly provided, it almost perfectly works. There is just a small hick up, which I'd like to understand/circumvent.
Issue1:
The table now shows the correct values! Thank you at that stage already.
However, if I include the exact dates for which Emil purchased something, the average time between purchases disappears. Is there a way to keep the variable visible in the table for each day?
Issue2:
Also, I can not use the measure in a visualization really. Since it, as you described, always calculates a difference between two values, I can not depict the average repurchase time in a KPI card, in a gauge or in a bar chart - which was the goal. Would you know how to adjust that I would be able to display that?
Similarly, when displaying in a table, I would want to show the average time between purchases of categories/products excluding the users - so averaging on total category level. How would that work?
Best regards and many thanks!