Forum Discussion
Lost Customers - Issues with DAX Calculation
- 10 years ago
Good point - you have to remove some filter from the CustomerLostDate column expression.
Try this one replacing the ADDCOLUMNS in original formula:
ADDCOLUMNS ( CALCULATETABLE ( VALUES ( Customer[CustomerCode] ), Sales ), "CustomerLostDate", CALCULATE ( MAX ( Sales[Invoice Date] ), ALLEXCEPT ( Customer, Customer[CustomerCode] ) ) + [Lost Days Limit] )
Thank you, Marco. That gives me the correct answer if I only have the Customer No in a pivot table. If I include the Customer Name in the pivot table (this is the attribute that changed over time), it counts them as lost. Is there a way to alter the calculation to change this behavior so I get consistent results in both pivots?
For example, I have a customer who bought something in December and then their name changed, then they had purchases in January and February.
Customer CustomerKey Customer No Customer Name EffectiveStart EffectiveEnd RowIsCurrent 1 1 Person A 1/1/1900 1 2/31/2015 0 2 1 Person A2 1/1/2016 1
SalesInvoice InvoiceDateKey InvoiceDate CustomerKey ProductKey SalesAmount 20151218 12/18/2015 1 3 10 20160129 1/29/2016 2 4 15 20160216 2/12/2016 2 5 20
Their pivot with just Customer No looks good (they are not counted as lost). But if I include Customer Name after the Customer Number, they are counted as lost in February, despite the fact that I am not using the CustomerKey (surrogate key) anywhere in the formula.
Good point - you have to remove some filter from the CustomerLostDate column expression.
Try this one replacing the ADDCOLUMNS in original formula:
ADDCOLUMNS (
CALCULATETABLE ( VALUES ( Customer[CustomerCode] ), Sales ),
"CustomerLostDate", CALCULATE (
MAX ( Sales[Invoice Date] ),
ALLEXCEPT ( Customer, Customer[CustomerCode] )
)
+ [Lost Days Limit]
)- Ashish_Mathur8 years agoSuper User
Hi zkazimov
Try this calculated field formula
=COUNTROWS(FILTER(SUMMARIZE(CALCULATETABLE(VALUES(SALES[CUSTOMER]),DATESBETWEEN('CALENDAR'[Date],EDATE(MIN('CALENDAR'[Date]),-1),max('CALENDAR'[Date]))),[CUSTOMER],"ABCD",[TOTAL SALES],"EFGH",[TOTAL SALES PREV PERIOD]),[EFGH]>0&&ISBLANK([ABCD])))Hope this helps.
- Ashish_Mathur8 years agoSuper User
- Meagan10 years agoMost Valuable Professional
Thanks so much, Marco. That did the trick. For anyone else who happens to need it, here is my full DAX calculation:
Lost Customers:=IF ( NOT ( MIN ( 'Date'[Full Date] ) > CALCULATE ( MAX ( Sales[Invoice Date] ), ALL ( Sales ) ) ), COUNTROWS ( FILTER ( ADDCOLUMNS ( FILTER ( CALCULATETABLE ( ADDCOLUMNS ( CALCULATETABLE ( VALUES ( Customer[Customer No] ), Sales ), "CustomerLostDate", CALCULATE ( MAX ( Sales[Invoice Date] ), ALLEXCEPT ( Customer, Customer[Customer No] ) ) + [Lost Days Limit] ), FILTER ( ALL ( 'Date' ), AND ( 'Date'[Full Date] < MIN ( 'Date'[Full Date] ), 'Date'[Full Date] >= MIN ( 'Date'[Full Date] ) - [Lost Days Limit] ) ) ), AND ( AND ( [CustomerLostDate] >= MIN ( 'Date'[Full Date] ), [CustomerLostDate] <= MAX ( 'Date'[Full Date] ) ), [CustomerLostDate] <= CALCULATE ( MAX ( Sales[Invoice Date] ), ALL ( Sales ) ) ) ), "FirstBuyInPeriod", CALCULATE ( MIN ( Sales[Invoice Date] ) ) ), OR ( ISBLANK ( [FirstBuyInPeriod] ), [FirstBuyInPeriod] > [CustomerLostDate] ) ) ) ) - zkazimov8 years agoHelper I
Hi Guys,
I need help understanding how to find lost customers. All I need is to find out customers who had sales last period, but not currnet period depending on the relative date filter selected. I don't understand concept used with "Lost Days Limit".
I have read http://www.daxpatterns.com/new-and-returning-customers/ multiple times. I have no issues with Return and New Customers Concept.
Thank you. Appreciated.
- Ashish_Mathur8 years agoSuper User
- zkazimov8 years agoHelper I
Hi Ashish_Mathur,
I want lost customers to be like in the image below for new customers. Links below for sample file and data source.
https://1drv.ms/u/s!ArZK-htpGmgl7iruP47UKkZYs0yR
- Ashish_Mathur8 years agoSuper User
Hi zkazimov,
To keep things simple, try this calculated field formula
=if(AND([TOTAL SALES PREV PERIOD]>0,[TOTAL SALES]=0),1,0)
In the Visual level filters section, apply a criteria of 1.
Hope this helps.
- zkazimov8 years agoHelper I
That works as a workaround, but not able to aggregate that measure to show on for example usign Card Visual. Also in the table see below how it is not aggreagted for total lost customers.
I need same effect as i have in the table for new customers.
- zkazimov8 years agoHelper I
This is great! Summarize Function did the job. Thanks a lot for time spent on this Appreciated.
- Anonymous6 years agoNot applicable
I am having same issue, could you please share the DAX you created ?
- Anonymous4 years agoNot applicable
This is a great calc. The problem Im having is that its counting a customer as lost that didnt buy for 12 consecutive months more than once in their 5 year history. Only the last 12 months with no sales shoudl be counted as lost. How do I get it to only grab the last purchase date. Wehn I wabt to displayit by month it shows as lost in prior years. thanks
- marcorusso4 years agoMost Valuable Professional
There is a new version of the pattern that considers new, lost, and recovered customers - it is more flexible and you should be able to adapt it to your requirements: