cancel
Showing results for
Did you mean:
Frequent Visitor

## COUNTDISTINCT(repeatCustomers) excluding previously counted repeatCustomers

Heyhey,

I've seen several 'how to count repeat customers?' posts but I have a specific question regarding repeat/recurring customers that I haven't seen anywhere else yet.

Repeat Customer: Someone who ordered one year ago today and made another purchase between one year ago today and today.

Example; Today (2020/02/25) looking back one year (2019/02/25) who ordered on that date? And from this specific customerset, who ordered another time between 2019/02/26 and 2020/02/25? Any customers that fit these criteria, label them as 'repeat customers' starting 2020/02/25.

EDIT: Important here is that, if a customer previously counted as repeat customer purchases another (third) time, he/she is not counted as a repeat customer on the day of the third purchase (or fourth, or firth etc.). A customer is counted as 'turning into a repeat customer' only once (at the second purchase, if it is within a year of the first). The same should be true for 'Future Repeat Customers'.

Future Repeat Customers: A customer who just ordered for a second time and his/her very first order was within a year ago.

Example; Today (2020/02/25) which customers placed their second order? From this specific customerset, whose first order was placed between 2019/02/26 and 2020/02/25? Any customers that fit these criteria, label them as 'future repeat customers' starting 2020/02/25 (until 2021/02/25 where they become 'repeat customers').

I'm looking to create measures from these definitions. I would like to count both repeat customers and future repeat customers on a daily basis (aggregating them weekly monthly or yearly when necessary).

I've been messing around with DAX syntax but I'm still a beginner... Below is what I have so far (on repeat customers) but I believe this measure is way to strict somehow (giving me too few repeat customers). I'm suspecting the logic might be incorrect also...

Whoever can help me, much appreciated 🙂

Repeat customers from last 365 days =
VAR buyingPeriod = DATESINPERIOD(Calender[DateKey], LASTDATE(Calender[DateKey]), -365, DAY)

VAR previousDateCustomers = CALCULATETABLE(VALUES('Orders'[user_id]),
ALL('Calender'[Month Number],'Calender'[Year])
, firstDateInPeriod
)

ALL('Calender'[Month Number],'Calender'[Year])
)

VAR beforePreviousDateCustomers = CALCULATETABLE(VALUES(Orders[user_id]),
ALL(Calender[Month Number], Calender[Year])
, Calender[DateKey] < firstDateInPeriod
)

VAR repeatCustomers = EXCEPT(INTERSECT(previousDateCustomers, buyingPeriodCustomers), beforePreviousDateCustomers)

RETURN COUNTROWS(repeatCustomers)
1 ACCEPTED SOLUTION

Accepted Solutions
Frequent Visitor

## Re: COUNTDISTINCT(repeatCustomers) excluding previously counted repeatCustomers

Hey @v-diye-msft ,

I've actually figured out a solution to both the 'reapeat customers' and 'future repeat customers' issue. I can give a short description here:

1) Add the following date columns to the orders table

 Column Name DAX PreviousOrderDate CALCULATE(MAX(Orders[Order Date]), FILTER(Orders, Orders[Customer_id]=EARLIER(Orders[Customer_id]) && Orders[Order Date]EARLIER(Orders[Order Date])) InitialChurnDate IF(NOT(Orders[FirstOrderDate] = BLANK()), Orders[FirstOrderDate] + 365)

2) Create the following measure:

 Measure Name DAX repeatCustomer COUNTROWS(CALCULATETABLE(VALUES(Orders[Customer_id]), FILTER(Orders, Orders[PreviousOrderDate] = Orders[FirstOrderDate] && Orders[TimeBetweenPurchases] <= 365)))

For summarizing repeat customers use the InitialChurnDate as date aggregator. This way, it shows which customers turn into repeat customers (i.e., having bought a second time between their first purchase and exactly 1 year after that).

For summarizing future repeat customers use the regular order date as aggregator (From the customers who ordered on that date it checks to see if it is the second order. If it is the second order, and is within a year from the first order, the customer will be counted as future repeat customer (i.e., the customer automatically becomes a repeat customer on the date exactly a year from the their first purchase).

I know these are kind of awkward definitions for repeat/returning customers, but that's what I have to work with for now...

I consider this question answered, thanks for the help. Still, if anyone finds a more elegant solution (one that doesn't require 4 extra date columns), I would love to hear!

4 REPLIES 4
Resolver II

## Re: COUNTDISTINCT(repeatCustomers) excluding previously counted repeatCustomers

Hi,

Why not count it agains a specific day in a calendar?

- Create a calender with New Table -> Table = CALENDER(Mindate,Maxdate)

- Create a calculated column in this date table

``````Cust_this_day =
CALCULATE(DISTINCTCOUNT(order_table[customer_id]);
FILTER(order_table;order_table[order_date] = date_table[date])
) ``````

- You now can create a visual using the date hierarchy (year, month, q, day) to summarize your results, use MAX - not SUM.

Highlighted
Frequent Visitor

## Re: COUNTDISTINCT(repeatCustomers) excluding previously counted repeatCustomers

Hey Tijn,

Thanks for your response. I believe your solution gives me a peak number of customers in a particular time period. However, I'm looking for counts of repeat/returning/recurring customers after their first purchase, counted directly 1 year after their first purchase.

Community Support

## Re: COUNTDISTINCT(repeatCustomers) excluding previously counted repeatCustomers

Hi @Ramonn

you might consider creating pbix file that will contain some sample data (remove the confidential info), upload the pbix to onedrive or dropbox and share the link to the file. Please do not forget to describe the expected results based on this sample data.

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
Frequent Visitor

## Re: COUNTDISTINCT(repeatCustomers) excluding previously counted repeatCustomers

Hey @v-diye-msft ,

I've actually figured out a solution to both the 'reapeat customers' and 'future repeat customers' issue. I can give a short description here:

1) Add the following date columns to the orders table

 Column Name DAX PreviousOrderDate CALCULATE(MAX(Orders[Order Date]), FILTER(Orders, Orders[Customer_id]=EARLIER(Orders[Customer_id]) && Orders[Order Date]EARLIER(Orders[Order Date])) InitialChurnDate IF(NOT(Orders[FirstOrderDate] = BLANK()), Orders[FirstOrderDate] + 365)

2) Create the following measure:

 Measure Name DAX repeatCustomer COUNTROWS(CALCULATETABLE(VALUES(Orders[Customer_id]), FILTER(Orders, Orders[PreviousOrderDate] = Orders[FirstOrderDate] && Orders[TimeBetweenPurchases] <= 365)))

For summarizing repeat customers use the InitialChurnDate as date aggregator. This way, it shows which customers turn into repeat customers (i.e., having bought a second time between their first purchase and exactly 1 year after that).

For summarizing future repeat customers use the regular order date as aggregator (From the customers who ordered on that date it checks to see if it is the second order. If it is the second order, and is within a year from the first order, the customer will be counted as future repeat customer (i.e., the customer automatically becomes a repeat customer on the date exactly a year from the their first purchase).

I know these are kind of awkward definitions for repeat/returning customers, but that's what I have to work with for now...

I consider this question answered, thanks for the help. Still, if anyone finds a more elegant solution (one that doesn't require 4 extra date columns), I would love to hear!

Announcements

#### Announcing the New Spanish Forum

Do you need help in Spanish? Check out our new Spanish community section.

#### April 2020 Community Highlights

Info on our Super Users, MBAS content and badges, and updates to our support articles. - Read the full Community Highlights.

#### MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

Top Solution Authors
Top Kudoed Authors