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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Identifying matching dates by range between two tables

Hello - 

 

I need to identify matching employee id and date values between two tables. The first table is for Travel. 

 

TRAVEL

employee idtravel start datetransaction amount ($)Desired New Column 'Match?' 
2580812/10/2021739.52yes
2872712/28/2021362.20no
3078712/30/2021671.62no
024711/1/2022170.92yes
101421/1/2022405.98yes

 

Second table is for training. 

TRAINING

employee idon date
2580812/10/2021
287273/9/2021
307874/30/2021
0247112/31/2022
101421/2/2022


My goal is to identify what travel is training-related so that we can determine travel costs for training programs. To do this (I think) I need to identify matching employee id/travel start date and employee id/on date values and create a new column with yes/no to identify matches and allow me to filter non-training travel out. I'd like to count travel start dates that are one day before or after Training on date as a match.

 

I'm stuck.  Any help will be very much appreciated.

2 ACCEPTED SOLUTIONS
v-xinruzhu-msft
Community Support
Community Support

Hi @Anonymous 

You can refer to the following calculated column/

Match =
VAR _predate = [travel start date] - 1
VAR _nextdate = [travel start date] + 1
VAR _values = { _predate, _nextdate, [travel start date] }
VAR _lookup =
    LOOKUPVALUE ( TRAINING[on date], TRAINING[employee id], TRAVEL[employee id] )
RETURN
    IF ( _lookup IN _values, "yes", "no" )

vxinruzhumsft_0-1684374504904.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

Assuming no repetitions of Emp ID in the training table, create a relationship (Many to One and Single) from the Travel table to the Training table.  Write this calculated column formula in the first table

Match = if(or(related('Training'[on date]='Travel'[travel start Date],abs(related('Training'[on date]-'Travel'[travel start Date])=1),"Yes","No")


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

Assuming no repetitions of Emp ID in the training table, create a relationship (Many to One and Single) from the Travel table to the Training table.  Write this calculated column formula in the first table

Match = if(or(related('Training'[on date]='Travel'[travel start Date],abs(related('Training'[on date]-'Travel'[travel start Date])=1),"Yes","No")


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-xinruzhu-msft
Community Support
Community Support

Hi @Anonymous 

You can refer to the following calculated column/

Match =
VAR _predate = [travel start date] - 1
VAR _nextdate = [travel start date] + 1
VAR _values = { _predate, _nextdate, [travel start date] }
VAR _lookup =
    LOOKUPVALUE ( TRAINING[on date], TRAINING[employee id], TRAVEL[employee id] )
RETURN
    IF ( _lookup IN _values, "yes", "no" )

vxinruzhumsft_0-1684374504904.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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