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
ManjunathaEP
Helper II
Helper II

Return Customers count within 2 years

Hello,

 

Thank you in advance for helping me with the below issue. Please find the sample data given below and I would like to calculate the count of return customers within 2 years from a previous purchase.

Ex: If customer 1st purchase dated 01/Jan/2016 and next purchase dated 01/Jul/2017... I should get the count of the customer as a return. 

Order NoOrder DateCustomerRev Class
11101-Jan-16ABCApple
11101-Jan-16ABCOrange
22201-Jan-16XYZOrange
33310-Jul-16ABCOrange
44401-Jul-17YRPApple
55525-Aug-17ABCOrange
66610-Jul-18XYZOrange
77708-Aug-18YRPApple
77930-Sep-18ABCOrange
88810-Sep-19XYZOrange
88810-Sep-19XYZApple
99925-Sep-19ABCOrange

 

Expected count for Return Customers 
 2016201720182019
ABC1111
XYZ   1
YRP  1 

 

Please do the needful

1 ACCEPTED SOLUTION

Hi, @ManjunathaEP 

Thank you for your feedback.

I am not 100% sure how your desired outcome looks like in the Calculated Column, but please check the below picture and the link down below.

 

Picture1.png

 

Expected Result CC =
VAR currentorderno = 'Table'[Order No]
VAR currentdate = 'Table'[Order Date]
RETURN
IF (
COUNTROWS (
FILTER (
'Table',
'Table'[Customer] = EARLIER ( 'Table'[Customer] )
&& 'Table'[Order No] <> currentorderno
&& 'Table'[Order Date]
>= DATE ( YEAR ( currentdate ) - 2, MONTH ( currentdate ), DAY ( currentdate ) )
&& 'Table'[Order Date] < currentdate
)
) > 0,
"return",
"new"
)

 

 

https://www.dropbox.com/s/qyxu6eb39ic43ma/manjunathaEPv2.pbix?dl=0 

 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

5 REPLIES 5
Jihwan_Kim
Super User
Super User

Hi, @ManjunathaEP 

Please check the below picture and the sample pbix file's link down below.

 

Picture1.png

 

Expected Result Measure =
VAR currentcustomer =
MAX ( 'Table'[Customer] )
VAR recenttwoyears =
COUNTROWS (
CALCULATETABLE (
VALUES ( 'Table'[Customer] ),
FILTER (
ALL ( 'Table' ),
'Table'[Customer] = currentcustomer
&& 'Table'[Order Date] < MAX ( 'Table'[Order Date] )
&& 'Table'[Order Date]
>= DATE ( YEAR ( MAX ( 'Table'[Order Date] ) ) - 2, MONTH ( MAX ( 'Table'[Order Date] ) ), DAY ( MAX ( 'Table'[Order Date] ) ) )
)
)
)
RETURN
IF (
ISFILTERED ( 'Table'[Customer] ) && ISFILTERED ( 'Table'[Year] ),
IF ( COUNTROWS ( VALUES ( 'Table'[Customer] ) ) > 0 && recenttwoyears > 0, 1 )
)
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thank you so much for your support, unfortunately, it did not work for me for all the years. It calculated only for 2016 and 2017 and no values after 2018. I inserted a new column and calculated another method like below... but this measure also not worked correctly for 2019... can u please help on this.

ManjunathaEP_0-1623213251405.png

Measure I used to create new column:

New/Return<2years = VAR rule1=CALCULATE(DISTINCTCOUNT('Table'[Customer]),Filter(ALLEXCEPT('Table','Table'[Customer]),'Table'[Order Date]<earlier('Table'[Order Date])))
VAR Calc=CALCULATE(min('Table'[Order Date]),Filter(ALLEXCEPT('Table','Table'[Customer]),'Table'[Order Date]<earlier('Table'[Order Date])))
VAR rule2=if(NOT(ISBLANK(Calc)),DATEDIFF(Calc,'Table'[Order Date],DAY))
RETURN
IF(OR(rule1=0,rule2>730),"New","Return")

Hi, @ManjunathaEP 

Thank you for your feedback.

My formula is for creating a calculated measure, not a calculated column. The expected result that was shown in the initial question was a matrix type. So, I thought you wanted to see it by creating a measure, not a calculated column.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hi Jihwan, I am sorry for the confusion. Yes, I requested help on the calculated measure. Later, I was working on the other alternatives and I tried creating a calculated column. If possible, request you to help and correct me the calculated column measure.

 

You are always supportive, thank you so much for your guidance.

Hi, @ManjunathaEP 

Thank you for your feedback.

I am not 100% sure how your desired outcome looks like in the Calculated Column, but please check the below picture and the link down below.

 

Picture1.png

 

Expected Result CC =
VAR currentorderno = 'Table'[Order No]
VAR currentdate = 'Table'[Order Date]
RETURN
IF (
COUNTROWS (
FILTER (
'Table',
'Table'[Customer] = EARLIER ( 'Table'[Customer] )
&& 'Table'[Order No] <> currentorderno
&& 'Table'[Order Date]
>= DATE ( YEAR ( currentdate ) - 2, MONTH ( currentdate ), DAY ( currentdate ) )
&& 'Table'[Order Date] < currentdate
)
) > 0,
"return",
"new"
)

 

 

https://www.dropbox.com/s/qyxu6eb39ic43ma/manjunathaEPv2.pbix?dl=0 

 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

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.