Forum Discussion
Repeat Customer
Hi,
Good Day!
Following is the data table:
| OrderDate | Distributor Code | OutletCode | SRName | Category | SKUCode | OrderKG | SalesKG |
| 9/1/2019 | 14413 | 100033897 | Shipon | DDP | 403 | 0.48 | 0.48 |
| 9/2/2019 | 14413 | 100033897 | Shipon | DPP | 404 | 1.44 | 1.44 |
| 9/3/2019 | 14413 | 100033897 | Shipon | DDP | 405 | 0.96 | 0.96 |
| 9/3/2019 | 14413 | 100033897 | Shipon | DDP | 403 | 0.96 | 0.96 |
| 9/1/2019 | 14413 | 100033885 | Shipon | DPP | 404 | 1.44 | 1.44 |
| 9/2/2019 | 14413 | 100033885 | Shipon | DDP | 405 | 0.96 | 0.96 |
| 9/3/2019 | 14413 | 100033899 | Shipon | DDP | 403 | 0.48 | 0.48 |
Based on above table, want to calculate following result by using DAX measures in power BI
By Category, number of repeat customer:
| Category | Repeat Customer # |
| DDP | 1 |
| DPP | 0 |
| Total | 2 |
Thanks in advance :)
Hi morab ,
below is my proposed solution: a formula repeatCustomer that counts the repeat customer based on the chosen category.
RepeatCustomer = VAR customerTable = ADDCOLUMNS(VALUES('Table'[OutletCode]), "numberOfPurchases", CALCULATE(COUNTX('Table', [OutletCode]))) RETURN SUMX(customerTable, IF([numberOfPurchases]>1,1,0))And here is a screenshot:
I hope this is what you were looking for.
Regards,
LC
Interested in Power BI finance templates? Check out my blog at www.finance-bi.com
Hi morab ,
I believe I found the difference: in Excel, you are counting as 'repeat customers' only customers that buy on at least 2 different dates. The formula I proposed counts instead as 'repeat customers' any customer that has more than one transaction, even if the transaction is on the same date.
As an example, outlet code 100032940 for category IFFO: this outlet bought 2 times both on September 26. This customer (2 transactions but on the same day) is not counted in the Excel, but is counted in Power BI.
To have a count based on different days only, I had to add a calculated table to the model. Here is the formula for the table:
Customer Table by Date = SUMMARIZE('Datatable','Datatable'[OutletCode],'Datatable'[OrderDate], 'Datatable'[Category])And here is the new measure, counting repeat customers based on different days:
RepeatCustomerDifferentDays = VAR selectedCategory = SELECTEDVALUE('Datatable'[Category]) VAR customerTable = CALCULATETABLE ( ADDCOLUMNS(VALUES('Customer Table by Date'[OutletCode]), "numberOfPurchases", CALCULATE(COUNTX('Customer Table by Date', [OutletCode]))) , 'Customer Table by Date'[Category]= selectedCategory ) RETURN SUMX(customerTable, IF([numberOfPurchases]>1,1,0))The result now matches the Excel:
The result now matches the Excel.
Here is the link for the PBI file: https://drive.google.com/open?id=1tjpQKf70VP4gqT-wrjWjL29j-SjlOtwI
Enjoy!
LC
Here is the new formula, I took the time to simplify it:
RepeatCustomerDifferentDays New = SUMX(VALUES('Datatable'[OutletCode]), VAR dates = CALCULATETABLE(VALUES('Datatable'[OrderDate])) RETURN IF(COUNTX(dates, [OrderDate])>1,1,0) )Hi morab ,
You can find my solution attached:
https://finance-bi.com/wp-content/uploads/2020/01/customer-transactions-by-month.zip
Here is how it works:
Outlet No = var numberOfMonths = SELECTEDVALUE('Number of Months'[number of month]) var outlets = VALUES('Table1'[OutletCode]) var purchaseByMonth = SELECTCOLUMNS(outlets, "outlets", [OutletCode], "months with purchase", SUMX(VALUES('Calendar'[Year Month Number]), var countTransactions = CALCULATE(COUNTROWS('Table1')) RETURN IF(countTransactions>0,1,0) ) ) var purchasedXMonths = COUNTX(FILTER(purchaseByMonth, [months with purchase]=numberOfMonths), [months with purchase]) RETURN purchasedXMonthsThe variable number OfMonths is equal to the number of month selected (for example: purchase in only 1 month, purchase in 2 months, etc)
The variable outlets has a list of all the outlets
The variable purchaseByMonth is a table with all the outlets and a column specifying on how many months the outlet bought the product
Finally, the variable purchasedXMonth counts the number of outlets that bought for a specified number of months (based on the variable number of months).Does this help you?
Regards
LC
Interested in Power BI and DAX templates? Check out my blog at www.finance-bi.com
34 Replies
- lc_financeSolution Sage
Hi morab ,
below is my proposed solution: a formula repeatCustomer that counts the repeat customer based on the chosen category.
RepeatCustomer = VAR customerTable = ADDCOLUMNS(VALUES('Table'[OutletCode]), "numberOfPurchases", CALCULATE(COUNTX('Table', [OutletCode]))) RETURN SUMX(customerTable, IF([numberOfPurchases]>1,1,0))And here is a screenshot:
I hope this is what you were looking for.
Regards,
LC
Interested in Power BI finance templates? Check out my blog at www.finance-bi.com
- morabAdvocate I
Thanks a lot for the solution :smileyhappy:
lc_finance wrote:Hi morab ,
below is my proposed solution: a formula repeatCustomer that counts the repeat customer based on the chosen category.
RepeatCustomer = VAR customerTable = ADDCOLUMNS(VALUES('Table'[OutletCode]), "numberOfPurchases", CALCULATE(COUNTX('Table', [OutletCode]))) RETURN SUMX(customerTable, IF([numberOfPurchases]>1,1,0))And here is a screenshot:
I hope this is what you were looking for.
Regards,
LC
Interested in Power BI finance templates? Check out my blog at www.finance-bi.com
- morabAdvocate I
Hi,
I have used your suggested formula but not getting following outputs, Can you please help me to get the desire data:
Data Link: https://www.dropbox.com/sh/8wijg2pogouhg71/AABsUwlOLCYn0KwUWsCNYnIca?dl=0
Output:
- lc_financeSolution Sage
Hi morab ,
I tried applying the formula to your data and it works, see screenshot below.
For example, for Category IFFO there are 17 repeat customers, in the screenshot you have the customer code and how many transactions for each.
I also attach a link with the Power BI file: https://drive.google.com/file/d/1tjpQKf70VP4gqT-wrjWjL29j-SjlOtwI/view?usp=sharing
Regards,
LC
- morabAdvocate I
Thanks a lot for your prompt feedback :)
However, repeat customer for IFFO actually 8 rather than 17. I can calculate it in Ms. Excel easily.
Link ( https://www.dropbox.com/s/lj12jexql84iqmq/order_sales.xlsx?dl=0 )
but when I am going to do it in power Bi using your suggested formula its showing different result.
Looking forward to your prompt support :)
My Expected result is in below Screenshot:
- daedahHelper II
Excuse me please,
I want analysis repeat customer from previous month ,calculate following result by using DAX measures in power BI
Result this below
Month
Jan Total customer id repeat customer from previous month
Feb 600 120
. 630 100
.
.
Dec 820 200
Thank you so much for recommend
Raw data is
Date cust id custname amount(Baht)
- lc_financeSolution Sage
Hi daedah ,
You can use the following formula:
Repeat customer from previous month = SUMX( VALUES('Sales'[cust ID]), VAR currentCustomerHasSalesPreviousMonth = NOT COUNTX(FILTER('Sales',PREVIOUSMONTH(LASTDATE('Sales'[Date]))),[cust ID]) = BLANK() RETURN IF(currentCustomerHasSalesPreviousMonth, 1, 0) )This formula works as follows:
- VALUES creates a list of the customers with sales during the current month
- COUNTX counts the sales in the previous month for the customer having sales this month -> these are the repeat customers
- SUMX adds up all repeat customers
You can download from here an example of the Power BI file.
Does this help? Let me know if you have any more questions
LC
Interested in Power BI and DAX tutorials? Check out my blog at www.finance-bi.com
- daedahHelper II
Thank you so much 😍
- morabAdvocate I
Hi,
Good Day!
Based on attached table in links, want to calculate following result by using DAX measures in power BI:
Link: https://www.dropbox.com/s/rb8nto9l6b3xae6/200127_DB14412.xlsx?dl=0
Thanks in advance😊
- lc_financeSolution Sage
Hi morab ,
You can find my solution attached:
https://finance-bi.com/wp-content/uploads/2020/01/customer-transactions-by-month.zip
Here is how it works:
Outlet No = var numberOfMonths = SELECTEDVALUE('Number of Months'[number of month]) var outlets = VALUES('Table1'[OutletCode]) var purchaseByMonth = SELECTCOLUMNS(outlets, "outlets", [OutletCode], "months with purchase", SUMX(VALUES('Calendar'[Year Month Number]), var countTransactions = CALCULATE(COUNTROWS('Table1')) RETURN IF(countTransactions>0,1,0) ) ) var purchasedXMonths = COUNTX(FILTER(purchaseByMonth, [months with purchase]=numberOfMonths), [months with purchase]) RETURN purchasedXMonthsThe variable number OfMonths is equal to the number of month selected (for example: purchase in only 1 month, purchase in 2 months, etc)
The variable outlets has a list of all the outlets
The variable purchaseByMonth is a table with all the outlets and a column specifying on how many months the outlet bought the product
Finally, the variable purchasedXMonth counts the number of outlets that bought for a specified number of months (based on the variable number of months).Does this help you?
Regards
LC
Interested in Power BI and DAX templates? Check out my blog at www.finance-bi.com
- morabAdvocate I
SPOT ON!!!! 😁
Have already subscribed in your blog @finance-bi.com. Great Content. Looking forward to more to come for beginners (Like Me 😊)
- morabAdvocate I
Hi lc_finance
Good Day!
I have the customer transaction data set in the following link. I am trying to create a DAX measure to get the number of repeat customers who have purchased both in base month & any selected month.
For example, Customer code - 100082181 have purchased in October'2019 (Which is the base month). But not purchase in November'2019. So he will not consider as a repeat customer of Nov'19. But have purchased in Dec'19 so he will consider as a repeat customer for Dec'19
Expected Result: In Nov'2019, 28 repeat customers & In Dec'2019, 35 repeat customers considering Oct'2019 as the base month.
Sample data: https://drive.google.com/file/d/1GBrpvtgWkNFPvzNUuZ0a4rB4SXq4prlU/view
Thanks in advance 🙂