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
sbenzaquen
Helper I
Helper I

Add columns + related function with many-to-many relationship / merging two calculated tables

Hi,

 

I would like to merge the following two calculated table:

 

Table 1: Year/month - team - team count - working days

Table 2: Year/month - team -  days-off

 

 

I would like to bring the days-off data over to table 1 as an additional column. I tried using ADDCOLUMNS+ RELATED functions but is not working because i.) they have a many-to-many relationships and ii) they are calculated tables I can't merge them using PQ which would be ideal as the days-off result will depend on two variables the month/year and team.

 

How could anyone please help me to solve this issue?

 

Thank you in advance,

Salvador

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @sbenzaquen ,

 

To my knowledge, RELATED() works only for side 1 of the relationship.

Since the relationship in your data is Many to Many,it's suggested to use RELATEDTABLE() instead.

 

In addition, if the days-off is unique based on each YearMonth and Team, you could use LOOKUPVALUE() like this:

Dayoff = LOOKUPVALUE('Table2'[Days-off], 'Table2'[Year/Month],'Table1'[Year/Month],'Table2'[Team],'Table1'[Team])

lookupvalue.PNG

If it does not make sense ,please provide me with more details about your table and your problem or share me with your pbix file after removing sensitive data.

 

Best Regards,
Eyelyn Qin
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

2 REPLIES 2
v-eqin-msft
Community Support
Community Support

Hi @sbenzaquen ,

 

To my knowledge, RELATED() works only for side 1 of the relationship.

Since the relationship in your data is Many to Many,it's suggested to use RELATEDTABLE() instead.

 

In addition, if the days-off is unique based on each YearMonth and Team, you could use LOOKUPVALUE() like this:

Dayoff = LOOKUPVALUE('Table2'[Days-off], 'Table2'[Year/Month],'Table1'[Year/Month],'Table2'[Team],'Table1'[Team])

lookupvalue.PNG

If it does not make sense ,please provide me with more details about your table and your problem or share me with your pbix file after removing sensitive data.

 

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

Thank you @v-eqin-msft .

 

Your solution was not working initially because I the same year/month multiple times for one team. But I fixed it using Summerize + Roll up function.

 

All working well now.

 

Thanks,

Salvador

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.