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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Kavya_2001
Regular Visitor

How to calculate days since each customer’s last purchase?

Hey everyone,

I’m working on a Power BI dashboard where I need to show how many days it's been since each customer last made a purchase.

The goal is to quickly identify which customers haven’t ordered in a while so the sales team can follow up accordingly. I already have the Customer and OrderDate fields in my dataset, but I'm quite struck on how to calculate the "days since last purchase" dynamically in a measure.

Has anyone implemented something like this before?
Ideally, I’d like to show this in a table with one row per customer and a column showing how many days have passed since their last transaction.

Appreciate any help or DAX suggestions!

Thanks in advance! 

1 ACCEPTED SOLUTION
Abhilash_P
Kudo Kingpin
Kudo Kingpin

Hi @Kavya_2001 

Something like below data funtions might resolve your issue i think
Days Since Last Purchase = 
DATEDIFF(
    CALCULATE(MAX('SalesData'[OrderDate]), ALLEXCEPT('SalesData', 'SalesData'[Customer])),
    TODAY(),
    DAY
)


Thanks

View solution in original post

3 REPLIES 3
Abhilash_P
Kudo Kingpin
Kudo Kingpin

Hi @Kavya_2001 

Something like below data funtions might resolve your issue i think
Days Since Last Purchase = 
DATEDIFF(
    CALCULATE(MAX('SalesData'[OrderDate]), ALLEXCEPT('SalesData', 'SalesData'[Customer])),
    TODAY(),
    DAY
)


Thanks

burakkaragoz
Community Champion
Community Champion

Hi @Kavya_2001 ,

 

Just dropping in to say the answer above is totally solid and covers what you need. You can calculate the days since last purchase with that DAX setup, and it’ll work perfectly for table visual with one row per customer.

Quick tip though—sometimes if you have multiple sales tables or more complex data models (like inactive relationships, or you want to ignore some extra filters), you might need to tweak the CALCULATE part. But for standard setup, the formula shared should do the trick just fine.

If you run into any weird results or edge cases (like customers with no purchases at all showing up as blank or with weird numbers), let me know and can help with some workarounds or extra tweaks.

If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, would be grateful for 'Kudos' if you found my response helpful.
translation and formatting supported by AI

DataNinja777
Super User
Super User

Hi @Kavya_2001 ,

 

To calculate how many days it's been since each customer's last purchase in Power BI, you can create a DAX measure using the DATEDIFF function. The idea is to find the most recent OrderDate for each customer, then calculate the number of days between that date and today. Assuming your table is called 'Sales' and it contains the columns 'Customer' and 'OrderDate', the following DAX measure will give you the result:

Days Since Last Purchase = 
DATEDIFF(
    CALCULATE(MAX('Sales'[OrderDate]), ALLEXCEPT('Sales', 'Sales'[Customer])),
    TODAY(),
    DAY
)

This measure works by evaluating the latest order date for each customer using MAX, keeping the context filtered to each individual customer with ALLEXCEPT, and then computing the day difference between that date and the current date. You can place this measure in a table visual alongside the customer name to see how many days have passed since their most recent transaction.

 

Best regards,

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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.