Forum Discussion

kevbrown1980's avatar
kevbrown1980
Frequent Visitor
11 months ago
Solved

Calculations

Hi

 

I have 2 table with joined, 1 table has my cost data and the other the volume data. The cost table is 1 line per team however the volume table is multiple row per department giving an overal volume amount. The table below might show it better. I need to multiple the team cost in table 1 by the Vol in table 2 however I only need 10 for example for Code 1, so basically the unique number in Vol per code. How do I do that?

 

Table A    Table 2    Result 
            
CodeTeamCost  CodeDeptVol  TeamTotal Cost
1Green £  200.00  1A10  Green £  2,000.00
2Yellow £  430.00  1B10  Yellow £  2,150.00
3Red £  127.00  1C10  Red £  1,524.00
4Orange £  267.00  1D10  Orange £  8,010.00
5Blue £  205.00  2A5  Blue £  4,305.00
     2B5    
     2R5    
     3C12    
     4H30    
     4D30    
     4R30    
     4T30    
     5H21    
     5J21    
     5F21    
     5T21    
     5G21    
     5D21    
     5S21    
  • Hi kevbrown1980 

     

    If the code in Table A is always unique, you can create a one-to-many single direction relationship from Table A to B on code. Then create this measure (assuming there's only one distinct vol value per team regardless of the department):

    total cost = 
    SUMX (
        VALUES ( TableA[Code] ),
        CALCULATE ( MAX ( TableB[Vol] ) ) * CALCULATE ( SUM ( TableA[Cost] ) )
    )
    

     

     

     

7 Replies

  • If you have a one-to-many relationship from 'Table A' to 'Table 2' you can create a measure like

    Total Cost = SUMX(
        'Table A',
        VAR Volume = SUMX(
            CALCULATETABLE(DISTINCT('Table 2'[Vol])),
            'Table 2'[Vol]
        )
        VAR Result = 'Table A'[Cost] * Volume
        RETURN
            Result
    )
  • Hi kevbrown1980 

     

    If the code in Table A is always unique, you can create a one-to-many single direction relationship from Table A to B on code. Then create this measure (assuming there's only one distinct vol value per team regardless of the department):

    total cost = 
    SUMX (
        VALUES ( TableA[Code] ),
        CALCULATE ( MAX ( TableB[Vol] ) ) * CALCULATE ( SUM ( TableA[Cost] ) )
    )
    

     

     

     

    • v-dineshya's avatar
      v-dineshya
      Community Support

      Hi kevbrown1980 ,

      We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet. And, if you have any further query do let us know.

       

      Regards,

      Dinesh

      • v-dineshya's avatar
        v-dineshya
        Community Support

        Hi @kevbrown1980 ,

        We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet. And, if you have any further query do let us know.

         

        Regards,

        Dinesh

  • Hi,

    You may write these calculated column formulas in Table1

    Volume = calculate(min('Table2'[Vol]),filter('Table2','Table2'[Code]=earlier('Table1'[Code])))

    Total = 'Table1'[Cost]*'Table1'[Volume]

    Hope this helps.