Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi,
I am new to DAX scripting and I trying to script the following condition:
Data:
Table 1:
| Customer ID | Date | Calls | Emails |
| 1 | 1/1/2018 | 2 | 3 |
| 1 | 1/2/2018 | 1 | 2 |
| 1 | 1/1/2019 | 2 | 3 |
| 2 | 1/1/2019 | 5 | 6 |
Table2:
| Customer ID | First Purchase Date |
| 1 | 5/6/2018 |
| 2 | 2/3/2019 |
Any help would be appreciated!
Thanks
Solved! Go to Solution.
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!
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!
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 37 | |
| 37 | |
| 33 | |
| 32 | |
| 29 |
| User | Count |
|---|---|
| 130 | |
| 88 | |
| 82 | |
| 68 | |
| 64 |