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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Filter Date from multiple tables

Hi,

 

I am new to DAX scripting and I trying to script the following condition:

  • I want to calculate All the sales calls and emails sent to customers before their 1st purchase date, for every customer.

 

Data:

Table 1:

Customer IDDateCallsEmails
11/1/201823
11/2/201812
11/1/201923
21/1/201956

 

Table2:

Customer IDFirst Purchase Date
15/6/2018
22/3/2019

 

Any help would be appreciated!

 

Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hello!

 

First, start by creating a one-to-many relationship from Table2 to Table1.

Then I created two measures to solve this, one for calls and one for emails:

 

Calls Before First Purchase Date = CALCULATE(SUM(Table1[Calls]), FILTER(Table1, Table1[Date] <= RELATED(Table2[First Purchase Date])))
Emails Before First Purchase Date = CALCULATE(SUM(Table1[Emails]), FILTER(Table1, Table1[Date] <= RELATED(Table2[First Purchase Date])))

Calculate the sum of the number of calls/emails for each Customer ID, but apply a filter such that the date of the emails are earlier than the first purchase date. Since we have created the one-to-many relationship between these two tables, the related function can find the corresponding first purchase date for the given Customer ID.

 

Hope this helps!

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hello!

 

First, start by creating a one-to-many relationship from Table2 to Table1.

Then I created two measures to solve this, one for calls and one for emails:

 

Calls Before First Purchase Date = CALCULATE(SUM(Table1[Calls]), FILTER(Table1, Table1[Date] <= RELATED(Table2[First Purchase Date])))
Emails Before First Purchase Date = CALCULATE(SUM(Table1[Emails]), FILTER(Table1, Table1[Date] <= RELATED(Table2[First Purchase Date])))

Calculate the sum of the number of calls/emails for each Customer ID, but apply a filter such that the date of the emails are earlier than the first purchase date. Since we have created the one-to-many relationship between these two tables, the related function can find the corresponding first purchase date for the given Customer ID.

 

Hope this helps!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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