Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

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: So...
  • Anonymous's avatar
    Anonymous
    6 years ago

    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 NameDAX
    PreviousOrderDateCALCULATE(MAX(Orders[Order Date]), FILTER(Orders, Orders[Customer_id]=EARLIER(Orders[Customer_id]) && Orders[Order Date]<EARLIER(Orders[Order Date]))
    FirstOrderDate
    CALCULATE(MIN(Orders[Order Date]), FILTER(Orders, Orders[Customer_id]=EARLIER(Orders[Customer_id]))
    TimeBetweenPurchases
    DATEDIFF(Orders[PreviousOrderDate], Orders[Order Date], DAY)
    NextOrderDate
    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 NameDAX
    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!