Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
jrkhockey33
Regular Visitor

Calculate the Number of Customers who have returned within 90 days of FIRST purchase

I want to get a count of customers who have made a second puchase within 90 days of their first purchase, and then I want to group by the month/year.  I think I am very close here. 

 

This is what I currently have:

 

Returning Customers =
VAR
    ExistingCustomers = VALUES( Sales[CustomerKey] )
VAR
    DateParameter = 90
RETURN
COUNTROWS(
    FILTER(
        ExistingCustomers,
        CALCULATE( COUNTROWS( Sales ),
            FILTER( ALLSELECTED('Calendar'[Date]),
                'Calendar'[Date] > ( MIN( 'Calendar'[Date] ) - DateParameter ) &&
'Calendar'[Date] < MIN( 'Calendar'[Date]) ) ) = 0 ) )
 
The "FILTER(ALLSELECTED..." is something I found on the internet using a date slider, which is not what I want. I don't care about that, I care about the very first purchase date and if that same customer purchased another time within 90 days. 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @jrkhockey33 ,

 

 

vstephenmsft_0-1649919959338.png

vstephenmsft_1-1649919972750.png

I did not use the calendar table, the relationship are as follows.

vstephenmsft_2-1649920034300.png

 

1.Create a measure to calculate the number of 90-day repurchasing for each customer.

Number of 90-day repurchasing =
CALCULATE (
    COUNT ( Sales[CustomerKey] ),
    FILTER (
        ALLSELECTED ( 'Sales' ),
        [CustomerKey] = MAX ( 'Sales'[CustomerKey] )
            && [OrderDate] > MAX ( 'Customer Table'[DateFirstPurchase] )
            && [OrderDate]
                <= MAX ( 'Customer Table'[DateFirstPurchase] ) + 90
    )
)

 

2.Create another measure to count the number of customers who repurchased within 90 days. 

Number of customers repurchasing =
CALCULATE (
    DISTINCTCOUNT ( 'Sales'[CustomerKey] ),
    FILTER ( 'Sales', [Number of 90-day repurchasing] >= 1 )
)

vstephenmsft_3-1649920293027.png

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

11 REPLIES 11
beachwaves18
New Member

Are you able to share how you got the Purchased within 90 Days %? I've been stuck on it for awhile

Anonymous
Not applicable

Hi @jrkhockey33 ,

 

You need to find the date of the first purchase first, then use the dax function to delimit the 90-day range.

Is it possible to provide some sample data and expected restuls?

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I am unable to find a way to attach a file to this post. 

 

I do have a column in the customers table that says "First Purchase Date" or we could do MIN(Sales[OrderDate]) to get the first order date. 

Anonymous
Not applicable

Hi  @jrkhockey33

Is it okay to provide some sample data in the following way? Without sample data, there is really difficult to start.

vstephenmsft_0-1649743887948.png

You could try DATESINPERIOD function like

DATESINPERIOD( 'Calendar'[Date], MIN(Sales[OrderDate])), 90, DAY )

Or just use 'Calendar'[Date] > MIN(Sales[OrderDate]) && 'Calendar'[Date] < MIN(Sales[OrderDate])+90 to ge the 90-day range.

 

And I doubt MIN(Sales[OrderDate]) to get the first order date seems too accurate.

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Customer Table:

CustomerKeyDateFirstPurchase
116021/11/2004 0:00
125174/21/2004 0:00
125182/2/2004 0:00
127141/20/2004 0:00

Sales:

OrderDateCustomerKeySalesOrderNumber
7/2/2003 0:0016688SO51189
7/7/2003 0:0018212SO51268
7/9/2003 0:0016702SO51300
7/10/2003 0:0018246SO51321

 

The calendar table is simply a table of dates and time attributes (Calendar is a one-to-many relationship to the sales table.)

 

Anonymous
Not applicable

Hi @jrkhockey33 ,

 

 

vstephenmsft_0-1649919959338.png

vstephenmsft_1-1649919972750.png

I did not use the calendar table, the relationship are as follows.

vstephenmsft_2-1649920034300.png

 

1.Create a measure to calculate the number of 90-day repurchasing for each customer.

Number of 90-day repurchasing =
CALCULATE (
    COUNT ( Sales[CustomerKey] ),
    FILTER (
        ALLSELECTED ( 'Sales' ),
        [CustomerKey] = MAX ( 'Sales'[CustomerKey] )
            && [OrderDate] > MAX ( 'Customer Table'[DateFirstPurchase] )
            && [OrderDate]
                <= MAX ( 'Customer Table'[DateFirstPurchase] ) + 90
    )
)

 

2.Create another measure to count the number of customers who repurchased within 90 days. 

Number of customers repurchasing =
CALCULATE (
    DISTINCTCOUNT ( 'Sales'[CustomerKey] ),
    FILTER ( 'Sales', [Number of 90-day repurchasing] >= 1 )
)

vstephenmsft_3-1649920293027.png

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Help Post!
Hello guys,

I found this thread relatable to my issue, where I have been stuck for several days.

As shown in the attached screenshot, I need to calculate monthly percentages for the 90-day and 3-month measures with DAX. Could you please help me?

Best regards,

 

Power BI Solution Format.jpg

Hi, 

Can you give me solution for the measure : Number of customer Who Returned Within Following 3 Months (Following 3 months means- i) If any customer's first purchase was in July, I want to know whether he bought again in Aug, Sept, or Oct. ii) If that customer bought twice in July, that doesn’t count. I only look for whether he came back in Aug-Oct. So July 1 first purchasers and July 31 first purchasers are exactly the same for this one.

Hi, I used the formula below to solve this question.

Purchasewithin3months =
VAR Customerlist = VALUESSales[CustomerKey] )
VAR Returndate = 90
VAR CountCustomers =  
COUNTROWS(
    FILTER(
        Customerlist,
        CALCULATE(
                COUNTROWS (Sales),
                FILTER(
                    ALLSELECTED ( 'Calendar' ),
                    'Calendar'[Date] >=  MIN ( Sales[OrderDate] )  &&
                    'Calendar'[Date] <=  MIN ( Sales[OrderDate]) + 90 &&
                     FORMAT('Calendar'[Date]"YYYYMM") <> FORMAT(MIN(Sales[OrderDate]), "YYYYMM")
            )
    ) > 0
)
)
RETURN
CountCustomers

The slight issue I had with my function is that where the customer purchased in the same, the month will be excluded thus making the count only 60days from date of first purchase.

I hope you find this useful.
 
Customers who made purchases within first 90days after first purchase and customers who purchased within 90days of first purchase but not in the same month.Customers who made purchases within first 90days after first purchase and customers who purchased within 90days of first purchase but not in the same month.

Do you have the DAX formula for purchased within 90 days?

tseayo
Frequent Visitor

Try this formula and let me know if this works for you:

PurchaseWithin3Months =
VAR CustomerList = VALUES(Sales[CustomerKey])
VAR CountCustomers =
    COUNTROWS(
        FILTER(
            CustomerList,
            CALCULATE(
                COUNTROWS(Sales),
                FILTER(
                    Sales,
                    Sales[CustomerKey] = EARLIER(Sales[CustomerKey]) &&
                    Sales[OrderDate] > CALCULATE(MIN(Sales[OrderDate]), ALLEXCEPT(Sales, Sales[CustomerKey])) &&
                    Sales[OrderDate] <= CALCULATE(MIN(Sales[OrderDate]), ALLEXCEPT(Sales, Sales[CustomerKey])) + 90
                )
            ) > 0
        )
    )
RETURN
CountCustomers

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors