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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
GuidoPinares
Helper I
Helper I

Track time activity

Hello Community,

 

Thanks so much for taking the time to review this, I have 3 tables as follows:

 

Sales (SaleID, DateOfSale, Customer, Quantity)

Activity (SaleID, DateOfActivity, Customer)

Customer (CustomerID, FullName)

 

I would like to track the activities that precedes a Sale, this means that someone from the company contact our customer prior to a Sale occurs, in the DB there are records when even though a customer has an activity related they never do a purchase, I want to get just those activities that has a Activity BEFORE the Sale occurs, If theres more than one Activity previous to the sale should be also consider.

 

GuidoPinares_0-1679948163272.png

 

For example in the previous image, a sale occurs on 2/4/2023 and also an Activity prior to that Sale on 2/1/2023. I want to consider only those cases, Any activity that occurs prior to a Sale and highlighted in a Matrix just as in the image. 

 

Thanks for any recommendation or help.

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@GuidoPinares , You can have new column like

 

New column =

var _cnt = countx(filter(Activity, Activity[Customer] = sales[customer] && Activity[Date] < sales[Date]) , Activity [Customer])

var _cntSalesbefore = countx(filter(sales, sales[Customer] = earlier(sales[customer]) && sales[Date] < earlier(sales[Date]))  , sales[Customer])

return

if(isblank(_cntSalesbefore ), _cnt, blank())

 

Returning count only when there are no sales before

 

refer if needed

refer 4 ways (related, relatedtable, lookupvalue, sumx/minx/maxx with filter) to copy data from one table to another
https://www.youtube.com/watch?v=Wu1mWxR23jU
https://www.youtube.com/watch?v=czNHt7UXIe8

 

Power BI DAX- Earlier, I should have known Earlier: https://youtu.be/CVW6YwvHHi8
https://www.youtube.com/watch?v=cN8AO3_vmlY&t=17820s

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
GuidoPinares
Helper I
Helper I

Thanks so much, the videos you sent help to understand even more the solution.

amitchandak
Super User
Super User

@GuidoPinares , You can have new column like

 

New column =

var _cnt = countx(filter(Activity, Activity[Customer] = sales[customer] && Activity[Date] < sales[Date]) , Activity [Customer])

var _cntSalesbefore = countx(filter(sales, sales[Customer] = earlier(sales[customer]) && sales[Date] < earlier(sales[Date]))  , sales[Customer])

return

if(isblank(_cntSalesbefore ), _cnt, blank())

 

Returning count only when there are no sales before

 

refer if needed

refer 4 ways (related, relatedtable, lookupvalue, sumx/minx/maxx with filter) to copy data from one table to another
https://www.youtube.com/watch?v=Wu1mWxR23jU
https://www.youtube.com/watch?v=czNHt7UXIe8

 

Power BI DAX- Earlier, I should have known Earlier: https://youtu.be/CVW6YwvHHi8
https://www.youtube.com/watch?v=cN8AO3_vmlY&t=17820s

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.