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
avanderschilden
Resolver I
Resolver I

Measure to display returning customers

Hello,

 

I have a very simple model;

 

Capture2.PNG

 

I want to calculate the distinct number of customers that did a sale in the past, but not in the last 180 days.

 

As you can see in the following table, customer with id 1 does a second sale on 2019-07-02 and therefore it is the only "returning" customer in my data set;

 

Capture3.PNG

 

The result I want to achieve is;

2019-07-02 | 1

 

In the result, 1 is not the id of the customer, but it means there is only 1 returning customer on this date, which did a sale on this date, does not have a sale in the last 180 days from 2019-07-02, but does have a sale older than 180 days from 2019-07-02.

 

The following measure is not producing any result;

Capture.PNG

 

What is the mistake in my measure?

 

Many thanks in advance!

4 REPLIES 4
Greg_Deckler
Community Champion
Community Champion

@marcorusso  wrote a quick measure for something like this: https://community.powerbi.com/t5/Quick-Measures-Gallery/New-and-Returning-Customers/m-p/168297

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thanks! I've seen this before but unfortunately it does not solve my problem. In Marco's example, a returning customer has an easier definition than in my example. My measure contains a mistake in one of the filter arguments which is the reason it does not produce the result I want.

marcorusso
Most Valuable Professional
Most Valuable Professional

Can you copy the code as a text instead of as a bitmap? It would be simpler to edit showing you possible improvements. There are two issues:
- calculation: you filter Sales[Date_ID] instead of Date[Date]
- performance: you have a very slow implementation of the calculation

@marcorusso 

I ended up with the following measure that produces the result I was looking for. As you mentioned on the sqlbi forum, this measure can be improved performance wise, so I will read the article you send me to see if I can implement the suggested performance improvements.

Reactivated Customers =

VAR CurrentUsers =
VALUES(Sales[customer_id])

VAR UsersLast180Days =
CALCULATETABLE(
VALUES(Sales[customer_id]),
FILTER (
ALL ( 'Dates' ),
Dates[Date] > MIN( Dates[Date] ) -180 && Dates[Date] < MIN( Dates[Date] ) -1))

VAR UserBefore180Days =
CALCULATETABLE(
VALUES(Sales[customer_id]),
FILTER(ALL(Dates),Dates[Date]<MIN(Dates[Date])-180))

RETURN
CALCULATE(
DISTINCTCOUNT(Sales[customer_id]),
FILTER (
ALL ( Sales[customer_id] ),
Sales[customer_id] IN CurrentUsers
&& Sales[customer_id] in UserBefore180Days
&& NOT Sales[customer_id] IN UsersLast180Days))

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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