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 create measures between two tables that have a many to many relationship

I need to solve how to create measures between tables that have many to many relationships.

 

I’ll describe the process and data

  • I have a table (TABLE A) that lists people and their allocated cost to “Systems”.  Each person can be allocated to one or more systems.
  • Each System rolls up to one or more Products.  (TABLE B) System costs can be allocated to one or more Products.
  • We then want to see the Roll up the cost for each product (Table C)

 

I need these to be measures (System to Product to COST)  and (Product COST) as we have other “attributes” on our people that we will use to filter, like Role and Location and as such want to see how they affect the rolled up numbers.

My challenge is around the Many to Many relationship of table A and table B.  How can I create a measure to sum the person cost per each system and product.  Table B will find the person cost records for each system and then multiply by the allocation to the product.

 

 Below is a rough example of how our data is structured.

 

many_to_Many.jpg

 

 

1 ACCEPTED SOLUTION

Hi @Anonymous 

 

Here is a little pseudocode as a description:

 

 

For each row from [Table B], do the following expression
     For each (related) row of the related [Table A], do the following expression
           Personnel costs from [Table A] * Allocation from [Table B]
     and then calculate the SUM
and then calculate the SUM

 

 

At first the allocated person cost of [Table A] ist calculated row by row (SUMX)

and then the SUM for [Table B] ist calculated row by row (SUMX) .

 

If I answered your question, please mark my post as solution, this will also help others.

Please give Kudos for support. 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


View solution in original post

10 REPLIES 10

Hi @Anonymous ,

 

You may download my PBIX file from here.
Hope this helps.

 

If I answered your question, please mark my post as solution, this will also help others.

Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Anonymous
Not applicable

Can't access the pbix file..  @mwegener 

2019-12-16_15-09-23.jpg

 

Hi @Anonymous ,

 

next try PBIX

 

If I answered your question, please mark my post as solution, this will also help others.

Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Anonymous
Not applicable

@mwegener 

same problem, message..  

Hi @Anonymous ,

 

The URL probably contained a problematic string

 

PBIX

 

If I answered your question, please mark my post as solution, this will also help others.

Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Anonymous
Not applicable

Thanks @mwegener   Appreciate the input/fedback...

 

I will review some more but ... I'm not sure off the top of my head that this will work.. You created a calculated column not a measure.

In my post I needed to do a "measure" so as to be able to use Attributes about people to "filter" the allocated Person Cost in the rollup to Product Costs... 

 

Example, if we had a attribute called "role" on Table A for each persons record(s).. (Role 1, Role 2, Role 3, etc.. ) then we would want to see the cost by "ROLE" .. futher we might also have an attribute called "Location"... 

 

Then the Cost at the Product Level could be broken down by Role and Location.. 

 

make sense?

 

 

 

Hi @Anonymous ,

 

take this...

 

M Allocate Person Cost = SUMX('Table B', SUMX(RELATEDTABLE('Table A'), 'Table A'[Person Cost] * 'Table B'[Allocat]))

 

If I answer you question, please mark my post as solution, this will also help others.

Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Anonymous
Not applicable

This appears to work, thanks a ton for your input/feedback.

 

.. as a "conclusion" and so as when others find this thread they can learn what is going on "under the covers";

could you "explain" how the nested Sumx functions are "working"..

 

M Allocate Person Cost = SUMX('Table B', SUMX(RELATEDTABLE('Table A'), 'Table A'[Person Cost] * 'Table B'[Allocat]))

  

Again thanks for your help!

Hi @Anonymous ,

 

has your question been answered?

 

If I answered your question, please mark my post as solution, this will also help others.

Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Hi @Anonymous 

 

Here is a little pseudocode as a description:

 

 

For each row from [Table B], do the following expression
     For each (related) row of the related [Table A], do the following expression
           Personnel costs from [Table A] * Allocation from [Table B]
     and then calculate the SUM
and then calculate the SUM

 

 

At first the allocated person cost of [Table A] ist calculated row by row (SUMX)

and then the SUM for [Table B] ist calculated row by row (SUMX) .

 

If I answered your question, please mark my post as solution, this will also help others.

Please give Kudos for support. 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


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.