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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Trying to create Lost Customers measure and getting out of memory error.

Hello . I was hoping someone could help me. I created the calc below for lost customers. It works great however when the range is expanded I get a memory error. this query uses more memory than is configured. Code is below. I have tried to add variables to it to optimize it but cant seem to get it to work. Any help or sugestions would be highly appreciated.

Lost UBP =
IF (
NOT (
MIN ( 'Calendar'[calendar_date] )
> CALCULATE ( MAX (Transactions[local_transaction_date] ), ALL ( Transactions) ) ),
COUNTROWS (
FILTER (
ADDCOLUMNS (
FILTER (
CALCULATETABLE (
ADDCOLUMNS (
CALCULATETABLE (
VALUES ( Partner[ParentPartnerID] ), Transactions),
"CustomerLostDate", [LastPurchaseDate]+ 365),
FILTER (
ALL ( 'Calendar' ),
AND (
'Calendar'[calendar_date] < MIN ( 'Calendar'[calendar_date] ),
'Calendar'[calendar_date] >= MIN ( 'Calendar'[calendar_date] )- 365))),
AND (
AND (
[CustomerLostDate] >= MIN ( 'Calendar'[calendar_date] ),
[CustomerLostDate] <= MAX ( 'Calendar'[calendar_date] )),
[CustomerLostDate] <=
CALCULATE ( MAX ( Transactions[local_transaction_date] ), ALL ( Transactions ) ) ) ),
"FirstBuyInPeriod", [FirstPurchaseDate]),
OR (
ISBLANK ( [FirstBuyInPeriod] ),
[FirstBuyInPeriod] > [CustomerLostDate] ) ) ) )
1 ACCEPTED SOLUTION
Anonymous
Not applicable

I actualy solved the issue. The calc is below. Thank you all for trying to help.

Lost customer =
VAR FirstDateSelected = FIRSTDATE( DATEADD ( 'Calendar'[calendar_date], 0, MONTH ) )
VAR LastDateSelected = LASTDATE( DATEADD ( 'Calendar'[calendar_date], 0, MONTH ) )
VAR CustomerLostDate = CALCULATE (
[LastPurchaseDate],
CALCULATETABLE (
Transactions,
FILTER (
ALL ( Partner ),
Partner[ParentPartnerID] = MAX ( Partner[ParentPartnerID] )
),
FILTER ( ALL ( 'Calendar' ), 'Calendar'[calendar_date] <= [LastPurchaseDate]) ) ) +365

RETURN
SUMX (
VALUES( Partner[ParentPartnerID] ),
IF (
CustomerLostDate>= FirstDateSelected
&& CustomerLostDate <= LastDateSelected, 1 ) )

View solution in original post

31 REPLIES 31
TheoC
Super User
Super User

@Anonymous okay, to remove all dates other than the specific and provide a 1 for Lost Customer, here is the measure:

 

mCustomer Type = 

VAR _1 = CALCULATE ( LASTDATE ( 'Transaction'[Purchase Date] ) , ALLEXCEPT ( 'Transaction' , Partner[PartnerID] ) , Transaction[Purchase Date] )
VAR _2 = IF ( INT ( TODAY() - _1 ) > 365.2 , 1 , BLANK() )

RETURN

MAXX ( FILTER ( 'Transaction' , 'Transaction'[Purchase Date] = _1 ) , _2 )

Hope this is it 🙂

 

Theo

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Anonymous
Not applicable

Nope. here is my calc below. the top table is the one with your new calc. The one below is the accuare one.

MKatsanevas_0-1644425962064.png

MKatsanevas_1-1644425981808.png

 

 

sevenhills
Super User
Super User

Check this article about Lost customers DAX 

https://www.daxpatterns.com/new-and-returning-customers/

 

You can avoid nested calculate tables ...

TheoC
Super User
Super User

Hi @Anonymous 

 

Can you provide the Table structures you're dealing with and some context to what fields you use to determine what a "Lost Customer" is?

 

Thanks in advance.

Theo

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Anonymous
Not applicable

Hi Theo the first purchase date is the min date where sales >0 same with last purchase date it's the max date where sales >0. We have the customer in the partner table the sales are in the transactions table and we have the calendar. We have sales that go back 10 years. A lost customer is a parent partner id that purchasesd in the past but not in the last 12 months. Any help would be appreciated 

Hi,

Write these measures:

Date of last sale = calculate(max(Data[sales date]),datesbetween(calendar[date],minx(all(calendar[date]),calendar[date]),max(calendar[date])))

Lost customers = countrows(filter(calculatetable(values(Partner[ParentPartnerID]),datesbetween(calendar[date],edate(min(calendar[date]),-11),max(calendar[date]))),[date of last sale]<edate(min(calendar[date]),-11)))

To your matrix visual, drag Year and Month from the Calendar Table and ParentPartnerID from the Partner table.

If this does not help, then share the link from where i can download your PBI file. 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

LOST UBP3 =
COUNTROWS (
FILTER (
CALCULATETABLE (
VALUES ( Partner[ParentPartnerID] ),
DATESBETWEEN (
'Calendar'[calendar_date],
EDATE ( MIN ( 'Calendar'[calendar_date],), -11 ),
MAX ( 'Calendar'[calendar_date],)
)
),
[LastPurchaseDate] < EDATE ( MIN ( 'Calendar'[calendar_date] ), -11 )
)
)
Im geting this error. thanks for your help
MKatsanevas_0-1644372253444.png

 

 
Anonymous
Not applicable

same thing Im geting 1's across all months. It needs to only show once in the month 12 months after last purchase date

MKatsanevas_0-1644372723631.png

 

Remove the extra comma in the MIN() function.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Anonymous okay, that makes a lot more sense.  So, theoretically speaking, the logic is as follows:

 

IF the MAX Purchase Date of a specific Partner ID is greater than 12 months old then flag the Partner ID as a Lost Customer otherwise ignore

 

Is the above correct?

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Anonymous
Not applicable

 Correct I want a 1 in the month 12 months after last purchase as that is the last month/date 

@Anonymous 

 

I'm not entirely sure what you mean by the 1 in the 12 months, sorry!  But hopefully the following helps.   Add a calculated column to your Partner table and use the following (adjust to your table and column names please):

 

Customer Type = 

VAR _1 = CALCULATE ( LASTDATE ( 'Transactions'[Purchase Date] ) , FILTER ( ALL ( 'Transactions' ) , Transaction[Partner ID] = Partner[Partner ID] ) )
VAR _2 = IF ( INT ( TODAY() - _1 ) > 365.25 , "Lost Customer" , "Active" )

RETURN

_2

Output of the above has been tested and runs like below - let me know how it goes k!

TheoC_0-1644369255927.png

 

Theo 🙂

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Anonymous
Not applicable

Also keep in mind that these fields are text not numbers

Transactions[ParentPartnerID]=MIN(Partner[ParentPartnerID]

@Anonymous the format of the fields does not affect the columns.  It's just that the formula I put together was adjusted and created the error.

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Anonymous
Not applicable

MKatsanevas_0-1644370101017.png

Im geting an error

 

Hi @Anonymous it's not reading the VAR _2 properly which implies that VAR _1 isn't closed off correctly. You may need another bracket at the end of VAR _1?

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

@Anonymous you aren't using the formula I provided. There is a "MAX" in your VAR _1 which is not the case in mine.

TheoC_0-1644370426630.png

 

Please use:

Customer Type = 

VAR _1 = CALCULATE ( LASTDATE ( 'Transactions'[Purchase Date] ) , FILTER ( ALL ( 'Transactions' ) , Transaction[Partner ID] = Partner[Partner ID] ) )
VAR _2 = IF ( INT ( TODAY() - _1 ) > 365.25 , "Lost Customer" , "Active" )

RETURN

_2

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Anonymous
Not applicable

The problem is I get the lost customer in every month. I only want a 1 in the month 12 months after so I can count all my lost customers. Like this:

MKatsanevas_1-1644371027904.png

 

Anonymous
Not applicable

I get an eror if I dont use the max since its a text column and not a number

MKatsanevas_0-1644370879408.png

 

Hi @Anonymous 

 

Did you create the Calculated Column in the Partner table or the Transaction table?  I put the formula together for the Partner table prior to realising what you wanted with the "1" in the month.

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.