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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
GuidoPinares
Helper I
Helper I

Searching a Previous date

Hi community,

 

This probably is a very easy problem but I am strugling with it, I hope you can help me.

 

Basically I have two different Tables:

 

Sales(CustomerID, DateSold)
Activities(CustomerID, ActivityDate)

 

I would like to find the First DateSold by CustomerID and store it in a Column as True or False and finally but most important look if that customer has an Activity prior to the DateSold, a good example is as follows:

Sales Data:

Customer IDDate Sold
A0011/1/2023
A0021/2/2023
A0011/15/2023
A0031/25/2023
A0042/1/2023
A0042/2/2023

 

Activities Data

 

Customer IDActivity Date
A0011/1/2023
A0021/1/2023
A0031/15/2023
A0042/2/2023
A0042/3/2023
A001

3/3/2023

 

The result should be in two calculate columns as follows:

 

Customer IDDate SoldFirst Purchase?Activities Before
A0011/1/2023TRUEFALSE
A0021/2/2023TRUETRUE
A0011/15/2023FALSE-
A0031/25/2023TRUETRUE
A0042/1/2023TRUEFALSE
A0042/2/2023FALSE-

 

The table Sales and Activities, both are able to have the same customerID more than once. We should focus if there is an activity prior to the First Time purchase of the customerID.

 

Thanks in advance for any suggestion or help!

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@GuidoPinares , NEw column

 

Activities Before= var _cnt = countx(Activies, Sales[Customer ID]=Activies[Customer ID] && Activies[Activity Date] <= Sales[Date Sold]) ,  Activies[Customer ID] )

return

if(isblank(_cnt), false(), true ())

 

 

First Purchase = var _date = minx(filter(Sales, Sales[Customer ID]= earlier(Sales[Customer ID])), Sales[Date Sold])
return
if(Sales[Date Sold] =_date, TRUE(), FALSE())

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

2 REPLIES 2
GuidoPinares
Helper I
Helper I

Thanks so much @amitchandak, I think other approach for the ACtivities before could be

Activities Before=

var _cnt2 = COUNTROWS(FILTER(Activities, Sales[PrescriberNPI] = Activities[new_cnpi] && Activities[Date] <= Sales[DateSold] && Activities[Date] >= (Sales[DateSold]-90)))
return

if(_cnt2>0, TRUE(), FALSE())
amitchandak
Super User
Super User

@GuidoPinares , NEw column

 

Activities Before= var _cnt = countx(Activies, Sales[Customer ID]=Activies[Customer ID] && Activies[Activity Date] <= Sales[Date Sold]) ,  Activies[Customer ID] )

return

if(isblank(_cnt), false(), true ())

 

 

First Purchase = var _date = minx(filter(Sales, Sales[Customer ID]= earlier(Sales[Customer ID])), Sales[Date Sold])
return
if(Sales[Date Sold] =_date, TRUE(), FALSE())

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.