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
sol3nsa
Regular Visitor

How to combine 2 tables with a many-to-many relationship

Hi Everyone, I keep thinking I've got the answer and then find a bizarre set of results which proves I haven't.

 

How do you combine 2 tables as follows:

sol3nsa_0-1663932529571.png

 

sol3nsa_1-1663932556833.png

 

Such that the following calculation is done:

Proj A = 0.3(1+2) + 1(3) + 0.2(2+3+4)
Proj B = 0.7(1+2) + 0.8(2+3+4)

 

To get: 

sol3nsa_2-1663932581108.png

 

I've set it up as a many-to-many relationship but I can't get the table visual to show this result correctly.

The tables are greatly simplified, they're actually 10s of 1000s of rows big.

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Here is your ideal data model with three dimensions and two facts.

lbendlin_0-1664053995301.png

Unfortunately this won't get you from the course hours to the project hours. 

You have a couple of options here, for example you could make the cross filter direction bidirectional

lbendlin_3-1664054293395.png

 

But that won't help with the calculation

lbendlin_4-1664054309216.png

So the next best option is a measure.

Hours = 
var a =  ADDCOLUMNS('Project User Allocation',"uh",var u=[User ID] return CALCULATE(sum('User Course Hours'[Hours]),'User Course Hours'[User ID]=u))
return sumx(a,[Headcount]*[uh])

lbendlin_5-1664055216105.png

There are other options but they won't be as good 🙂

See attached.

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

Here is your ideal data model with three dimensions and two facts.

lbendlin_0-1664053995301.png

Unfortunately this won't get you from the course hours to the project hours. 

You have a couple of options here, for example you could make the cross filter direction bidirectional

lbendlin_3-1664054293395.png

 

But that won't help with the calculation

lbendlin_4-1664054309216.png

So the next best option is a measure.

Hours = 
var a =  ADDCOLUMNS('Project User Allocation',"uh",var u=[User ID] return CALCULATE(sum('User Course Hours'[Hours]),'User Course Hours'[User ID]=u))
return sumx(a,[Headcount]*[uh])

lbendlin_5-1664055216105.png

There are other options but they won't be as good 🙂

See attached.

Many thanks Ibendlin - that's super

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.