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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Anonymous
Not applicable

Lost Customer Analytics

Hello all, 

 

I've been testing a measure to analyze lost customers but it is not working correctly.

 

The measure I am using is:

 

Advanced Lost Customers =

var CustomersPurchased = CALCULATETABLE(VALUES(transactions[CustomerCode]),
FILTER (ALL('Calendar'),
'Calendar'[Date]> MIN('Calendar'[Date]) - 365 &&
'Calendar'[Date] < MIN('Calendar'[Date]) - 180))

var PriorCustomers = CALCULATETABLE(VALUES(transactions[CustomerCode]),
FILTER(ALL('Calendar'),
'Calendar'[Date] > MIN('Calendar'[Date]) - 180 &&
'Calendar'[Date] < MIN('Calendar'[Date])))

return

COUNTROWS(EXCEPT(CustomersPurchased,PriorCustomers))*-1
 
The idea was, first create a table of all customer codes that have purchased on the last 180 days. Then create a table of customers that purchased in the last 360 days till 180 days.
 
Since a Lost Customer are the ones that did not purchase on the last 180 but purchased some month berfore, I counted the rows from customers appearing on table CustomersPurchased but not on table PriorCustomers.
 
The issue I am facing is the below:
 
Pedro_Okazaki_0-1628342366765.png

For this specific customer the last and only sales was on 15th january 2021.

 

Therefore it should be marked as lost 6 months from now, so August. But why is it also showing for the months after August? Need to remove these

 

Thank you in advance

1 ACCEPTED SOLUTION
v-kkf-msft
Community Support
Community Support

Hi @Anonymous ,

 

Because the date range you set in the "CustomersPurchased" variable is from the previous year to the half of the previous year, so the calculation results in 8/2020 - 1/2021 will include CustomerCode 11. 

 

image.png

 

You can try the following formula:

 

Advanced Lost Customers = 

var CustomersPurchased = 
CALCULATETABLE(
    DISTINCT(transactions[CustomerCode]),
    FILTER(
        ALL('transactions'),
        'transactions'[Date] >= EDATE( MIN('Calendar'[Date]), -7) &&
        'transactions'[Date] < EDATE( MIN('Calendar'[Date]), -6)
    )
)

var PriorCustomers = 
CALCULATETABLE(
    DISTINCT(transactions[CustomerCode]),
    FILTER(
        ALL('transactions'),
        'transactions'[Date] >= EDATE( MIN('Calendar'[Date]), -6) &&
        'transactions'[Date] < MIN('Calendar'[Date])
    )
)

return

COUNTROWS(EXCEPT(CustomersPurchased,PriorCustomers))*-1

vkkfmsft_0-1628572563400.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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

2 REPLIES 2
v-kkf-msft
Community Support
Community Support

Hi @Anonymous ,

 

Because the date range you set in the "CustomersPurchased" variable is from the previous year to the half of the previous year, so the calculation results in 8/2020 - 1/2021 will include CustomerCode 11. 

 

image.png

 

You can try the following formula:

 

Advanced Lost Customers = 

var CustomersPurchased = 
CALCULATETABLE(
    DISTINCT(transactions[CustomerCode]),
    FILTER(
        ALL('transactions'),
        'transactions'[Date] >= EDATE( MIN('Calendar'[Date]), -7) &&
        'transactions'[Date] < EDATE( MIN('Calendar'[Date]), -6)
    )
)

var PriorCustomers = 
CALCULATETABLE(
    DISTINCT(transactions[CustomerCode]),
    FILTER(
        ALL('transactions'),
        'transactions'[Date] >= EDATE( MIN('Calendar'[Date]), -6) &&
        'transactions'[Date] < MIN('Calendar'[Date])
    )
)

return

COUNTROWS(EXCEPT(CustomersPurchased,PriorCustomers))*-1

vkkfmsft_0-1628572563400.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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

 

daxer-almighty
Solution Sage
Solution Sage

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.