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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
beachwaves18
New Member

Percent of Customers Returned After 90 Days

Hello, I'm trying to create a DAX formula to find the % of customers that returned 90 days after their first purchase. I've spent several hours trying to create and recreate the formula but have not been able to replicate the numbers in the screenshot (for the 3rd or 4th column):

beachwaves18_0-1744331295458.png

 

 

I know there are other posts online about this, but none of the formulas have worked for me or any manipulations. I have a Sales table with CustomerKey and OrderDate. I have a Customer table with CustomerKey and DateFirstPurchase. I've spent many hours working on this and various formulas but this is the one I'm working with now:

Purchase within 90days(%) =

VAR Customerlist = VALUES( Sales[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]) + Returndate ) ) >0 ) )

Return DIVIDE(CountCustomers,[Customers])
 
 
Any help or insight is greatly appreciated.
 
2 ACCEPTED SOLUTIONS
antfr99
Resolver II
Resolver II

Hi @beachwaves18 

 

I suggest use these 4 measures :

 

1.

 

TotalCustomers = COUNTROWS(Customer)


2.

 

TotalCustomersByDateFirstPurchase =
CALCULATE(COUNTROWS(Customer), ALLEXCEPT(Customer, Customer[DateFirstPurchase - Customer Table]))

 

3.


CustomersReturnedWithin90Days =
VAR CustomersWithReturn =
CALCULATETABLE(
VALUES(Sales[Customer Key - Sales Table]),
FILTER(
Sales,
Sales[OrderDate - Sales Table] <= RELATED(Customer[DateFirstPurchase - Customer Table]) + 90
)
)
RETURN
COUNTROWS(CustomersWithReturn)

 

4.

 

PercentageReturnedAfter90Days =
DIVIDE([CustomersReturnedWithin90Days], [TotalCustomersByDateFirstPurchase])

 

to get the below  :

 

Customer.png

 

and without the customer name which is hopefully close to your requirement :

Customers2.png

Hope this helps

Antonio

View solution in original post

johnt75
Super User
Super User

Try

Purchase within 90days(%) =
VAR AllCustomers = [Customers]
VAR ReturnWithin90Days =
    SUMX (
        Customerlist,
        VAR FirstPurchase = Customerlist[DateFirstPurchase]
        VAR NumPurchases =
            CALCULATE (
                COUNTROWS ( Sales ),
                DATESINPERIOD ( 'Calendar'[Date], FirstPurchase + 1, 89, DAY )
            )
        VAR Result =
            IF ( NumPurchases > 1, 1 )
        RETURN
            Result
    )
VAR Result =
    DIVIDE ( ReturnWithin90Days, AllCustomers )
RETURN
    Result

View solution in original post

12 REPLIES 12
xbaby32
Frequent Visitor

Hello all,

 

I need help on this same exercise. I tried the posted solutions but I can't get the Customers Who Returned Within 90 Days measure to work. The measure is either returning a result far too low (3 in July 2001 but it should be ~142) or is returning the same result as Total Customers for each DateFirstPurchase Year/Month. Please help, thank you!

Make sure that your date table is marked as a date table. If it is then the basic logic behind the solution should work.

I double-checked and it is marked as a date table. My date table is calculated by:

Calendar = CALENDAR(min(Sales[OrderDate]),max(Sales[OrderDate]))
 
Could the fact that the Calendar table is derived from the Sales[OrderDate] matter?

No, that's fine.

Do you have a customer dimension table which includes their first purchase date ?

The correct solution is below. I am looking for the Percent of Customers Returned with 90 Days of First Purchase and Percent Who Returned Within the Following 3 Months.

 

xbaby32_0-1758242721040.png

 

 

There is a Sales table that is many:one with the Customers table by CustomerKey. The Customers table has a column DateFirstPurchase. I have a calculated table Calendar one:many with the Sales table by OrderDate.

 

Sales table   
ProductKeyOrderDateCustomerKeySalesOrderNumber
3767/2/03 0:0016688SO51189
3767/7/03 0:0018212SO51268
3767/9/03 0:0016702SO51300
3767/10/03 0:0018246SO51321
    
Customer table   
CustomerKeyAltCustomerKeyDateFirstPurchase 
21602116021/11/04 0:00 
22517125174/21/04 0:00 
22518125182/2/04 0:00 
22714127141/20/04 0:00 
    
Calendar table   
Date   
7/2/03 0:00   
7/7/03 0:00   
7/9/03 0:00   
7/10/03 0:00   

 

My intuition is that I need a COUNTROWS measure to count the rows of a table that has all CustomerKeys with a DateFirstPurchase value and the next OrderDate within 90 days of DateFirstPurchase. So if a CustomerKey has a DateFirstPurchase of 8/1/01 and the next OrderDate of 9/1/01, it would be counted. But if a CustomerKey has a DateFirstPurchase of 8/1/01 and the next OrderDate of 12/1/01, it would not be counted as it is outside the 90 day window. For the Customers who returned within the following three months, I assume we can just expand our "window" of next OrderDate from 90 days to 180 days from DateFirstPurchase.

 

The below measure is what has been proposed previously on this thread, but I tried it and it is not returning the proper result.

 

Purchase within 90days(%) =
VAR AllCustomers = [Customers]
VAR ReturnWithin90Days =
    SUMX (
        Customerlist,
        VAR FirstPurchase = Customerlist[DateFirstPurchase]
        VAR NumPurchases =
            CALCULATE (
                COUNTROWS ( Sales ),
                DATESINPERIOD ( 'Calendar'[Date], FirstPurchase + 1, 89, DAY )
            )
        VAR Result =
            IF ( NumPurchases > 1, 1 )
        RETURN
            Result
    )
VAR Result =
    DIVIDE ( ReturnWithin90Days, AllCustomers )
RETURN
    Result

 

My 'Calendar' table is calculated by: 

Calendar = CALENDAR(min(Sales[OrderDate]),max(Sales[OrderDate]))

Make sure that your calendar table is marked as a date table. Also, it is recommended that a calendar table should always include full years rather than starting and ending on random dates. You could use CALENDARAUTO() or adapt your current code to

Calendar =
CALENDAR (
    DATE ( YEAR ( MIN ( Sales[OrderDate] ) ), 1, 1 ),
    DATE ( YEAR ( MAX ( Sales[OrderDate] ) ), 12, 31 )
)

Separately, you could amend the original code to check if NumPurchases is greater than or equal to 1, currently it is checking for strictly greater than.

v-pgoloju
Community Support
Community Support

Hi @beachwaves18,

 

Just a gentle reminder — has your issue been resolved? If so, we’d be grateful if you could mark the solution that worked as Accepted Solution, or feel free to share your own if you found a different fix.

This not only closes the loop on your query but also helps others in the community solve similar issues faster.

Thank you for your time and feedback!

 

Best,

Prasanna Kumar

v-pgoloju
Community Support
Community Support

Hi @beachwaves18,

 

Just a gentle reminder — has your issue been resolved? If so, we’d be grateful if you could mark the solution that worked as Accepted Solution, or feel free to share your own if you found a different fix.

This not only closes the loop on your query but also helps others in the community solve similar issues faster.

Thank you for your time and feedback!

 

Best,

Prasanna Kumar

v-pgoloju
Community Support
Community Support

Hi @beachwaves18,

We wanted to kindly check in to see if everything is working as expected after trying the suggested solution. If there’s anything else we can assist with, please don’t hesitate to ask.

If the issue is resolved, we’d appreciate it if you could mark the helpful reply as Accepted Solution — it helps others who might face a similar issue.

 

Warm regards,

Prasanna Kumar

v-pgoloju
Community Support
Community Support

Hi @beachwaves18,

Thank you for reaching out to the Microsoft Fabric Forum Community.

Also, thanks to @johnt75  and @antfr99   for the prompt and helpful response.

Just following up to check if the solution shared by our Super User helped resolve your issue. If you're still facing difficulties or need further assistance, please let us know — we’re here to help!
If the response addressed your query, we kindly request you to mark it as Accepted Solution and click Yes if you found it helpful. This supports others in the community as well.

If you find this response helpful, please consider marking it as the accepted solution and giving it a thumbs-up to support others in the community.

Thank you & Regards,
Prasanna kumar

johnt75
Super User
Super User

Try

Purchase within 90days(%) =
VAR AllCustomers = [Customers]
VAR ReturnWithin90Days =
    SUMX (
        Customerlist,
        VAR FirstPurchase = Customerlist[DateFirstPurchase]
        VAR NumPurchases =
            CALCULATE (
                COUNTROWS ( Sales ),
                DATESINPERIOD ( 'Calendar'[Date], FirstPurchase + 1, 89, DAY )
            )
        VAR Result =
            IF ( NumPurchases > 1, 1 )
        RETURN
            Result
    )
VAR Result =
    DIVIDE ( ReturnWithin90Days, AllCustomers )
RETURN
    Result
antfr99
Resolver II
Resolver II

Hi @beachwaves18 

 

I suggest use these 4 measures :

 

1.

 

TotalCustomers = COUNTROWS(Customer)


2.

 

TotalCustomersByDateFirstPurchase =
CALCULATE(COUNTROWS(Customer), ALLEXCEPT(Customer, Customer[DateFirstPurchase - Customer Table]))

 

3.


CustomersReturnedWithin90Days =
VAR CustomersWithReturn =
CALCULATETABLE(
VALUES(Sales[Customer Key - Sales Table]),
FILTER(
Sales,
Sales[OrderDate - Sales Table] <= RELATED(Customer[DateFirstPurchase - Customer Table]) + 90
)
)
RETURN
COUNTROWS(CustomersWithReturn)

 

4.

 

PercentageReturnedAfter90Days =
DIVIDE([CustomersReturnedWithin90Days], [TotalCustomersByDateFirstPurchase])

 

to get the below  :

 

Customer.png

 

and without the customer name which is hopefully close to your requirement :

Customers2.png

Hope this helps

Antonio

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.