Forum Discussion

goyasor's avatar
goyasor
Frequent Visitor
9 years ago
Solved

Join on Date Range

Hello everyone,

 

I've been struglling with the following issue for a few days and hope someone might be able to help.

 

I'm trying to merge 2 tables on date range without success.

 

The first table shows a list users and when emails were sent to them:

Table 1  
UserEmail_DateEmail_Date_7days
112/07/201619/07/2016
113/10/201620/10/2016
212/07/201619/07/2016
325/07/201601/08/2016
319/12/201626/12/2016
412/07/201619/07/2016
511/08/201618/08/2016

 

 

The 2nd table is a list of when they responded:

Table 2 
UserResponse_Date
113/07/2016
115/07/2016
215/07/2016
221/07/2016
301/08/2016

 

 

I want table 1 to show the number of responses within 7 days, such that:

Table 1   
UserEmail_DateEmail_Date_7daysResponses_7days
112/07/201619/07/20162
113/10/201620/10/20160
212/07/201619/07/20161
325/07/201601/08/20161
319/12/201626/12/20160
412/07/201619/07/20160
511/08/201618/08/2016

0

 


I would appreciate some giudance in implementin this in Power Query(M)

 

  • goyasor,

     

    Why do you need to do this is Power Query? We can get this result in DAX easily.

    Column = CALCULATE(COUNT(Table2[User]),FILTER(Table2,Table2[User]=Table1[User]&&Table2[Response_Date]>=Table1[Email_Date]&&Table2[Response_Date]<=Table1[Email_Date_7days]))

     

    Regards,

    Charlie Liao

2 Replies

  • v-caliao-msft's avatar
    v-caliao-msft
    Microsoft Employee

    goyasor,

     

    Why do you need to do this is Power Query? We can get this result in DAX easily.

    Column = CALCULATE(COUNT(Table2[User]),FILTER(Table2,Table2[User]=Table1[User]&&Table2[Response_Date]>=Table1[Email_Date]&&Table2[Response_Date]<=Table1[Email_Date_7days]))

     

    Regards,

    Charlie Liao