Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Use a Measure to Sum Columns in Related Tables

I'm trying to use a measure to calculate the sum of a column in a related table two tables away. Basically I have a Product Table that has the ID of the product I want to get the cost of. It has a 1-to-Many relationship to a facility table which has the list of production facilities. That table has a Many-to-1 relationship to the Cost Table which shows the cost of each facility. 

 

I previously used calculated columns but am trying to just use measures. The issue is that I cannot seem to get it right. Either it creates duplicates when I put it into a table or or just repeats the same number for every product (effectively summing the entire cost table). 

 

Any help woudl be welcome. 

 

 

 

Product Table

ID
100
200
300

 

Facility Table:

IDFacility
100Prod1
100Finish
200Prod1
200Finish
300Prod2
300Prod3
300Finish

 

Cost Table:

FacilityCost
Prod11000
Prod21200
Prod31400
Finish500

 

 

Output of Measure through Power BI Table:

IDCost
1001700
2001700
3003100
  • Anonymous's avatar
    Anonymous
    7 years ago

    Assuming this is how your data model looks:

    You can use:

    Total Cost = CALCULATE( SUM ( Cost[Cost] ), Facility)

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Assuming this is how your data model looks:

    You can use:

    Total Cost = CALCULATE( SUM ( Cost[Cost] ), Facility)

    • Anonymous's avatar
      Anonymous
      Not applicable

      So, I think that my database is a bit more complicated because it has some blanks when it comes to costs and facilities. 

       

      The data model matched perfectly. 

      Output I'm getting:

      IDProduction Cost
      1001800
      2001800
      3001800
      4001800
      5001800
      6001800
      7001800
      8001800

       

       

      Tables:

       

      ID

      100
      200
      300
      400
      500
      600
      700
      800

       

      KeyIDFacility

      1100 
      2100 
      3100 
      4200Prod1
      5200Prod2
      6200Prod3
      7300Prod1
      8300Prod2
      9300Prod3
      10400Prod1
      11500Prod3
      12600Prod1

       

       

      Facility

      Prod1
      Prod2
      Prod3