Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

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 cust...
  • Anonymous's avatar
    Anonymous
    7 years ago

    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!