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

how to connect 2 many to many relationship tables

I have 2 tables. 
table 1:
emID    errandID  errandstarttime   errandendtime
001       AO1         20201202     20201203
001      AO2           20201202      20201204
001      AO3            20201213     20201214

table 2:

emID      callstart           callend

001         20201202     20201203

001         20201204     20201204

001        20201212       20201213

001         20201213      20201213

I need to add callstart and callend column from table 2 to table 1  based on the below conditions:
1)  emID are the same

2) callstart>=errandstart  and callend<= errandend

Normally one errand only includes one call, but there maybe exceptions. 


Please help how to make this out!  Thanks !
 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Create two new columns like

In table 1

 

call Start =

maxx(filter(Table2, Table2[callstart]>=Table1[errandstart] && Table2[callend]<=  Table2[errandend]  && Table2[emID] =Table1[emID] ) , Table2[callstart]) 

 

 

call End=

maxx(filter(Table2, Table2[callstart]>=Table1[errandstart] && Table2[callend]<=  Table2[errandend]  && Table2[emID] =Table1[emID] ) , Table2[called]) 

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

If for a single row in table 1, there are multiple rows in table 2, then what result do you expect?  Take a representative example and show the expected result.


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

Thank you!
Then I would expect for:
emID    errandID  errandstarttime   errandendtime  callstart1 callend1  callstart2   callend2

Share some data and show the expected result.


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

@Anonymous , Create two new columns like

In table 1

 

call Start =

maxx(filter(Table2, Table2[callstart]>=Table1[errandstart] && Table2[callend]<=  Table2[errandend]  && Table2[emID] =Table1[emID] ) , Table2[callstart]) 

 

 

call End=

maxx(filter(Table2, Table2[callstart]>=Table1[errandstart] && Table2[callend]<=  Table2[errandend]  && Table2[emID] =Table1[emID] ) , Table2[called]) 

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.