Forum Discussion

rachaelnelson's avatar
rachaelnelson
Frequent Visitor
9 years ago
Solved

Calculating Average Price Per Ton

I have a table of data that list all product sales.  I have a calculated column that calculates the cost / ton.  When I put this column in a matrix, each line calculates correctly but when I roll up the data to a product category or aggregate of the whole, the data is the average of each line ($226.73) and not total cost / total ton ($232.85).

 

How do I get the correct calculation in my matrix and in a card visual?  I would like to add a slicer with some the additional fields to filter to a particular date range, product category, etc but cannot do so until I figure out how to get the correct aggregate calculations.

 

Here is sample data:

ProductCostTonsCost/TonCategory
A5002250DA
A4752237.5DA
A4821.89255.026455DA
B2001200BF
B2100.9233.3333333BF
B2031.1184.5454545BF
 20708.89226.7342072
   232.8458943

 

  • Thank you, Vvelarde.  Your measure gave me the same values I was receiving with my current calculated column but it got me thinking and I was able to solve using the following:

    cost/ton = CALCULATE(SUM(Table1[COST])/SUM(Table1[Tons]))

3 Replies

  • Vvelarde's avatar
    Vvelarde
    Community Champion

    rachaelnelson

     

    Hi, use this measure:

     

    AVGCost-Tons = AVERAGEX(Table1,Table1[Cost/Ton])

     

    Regards

     

    Victor

    Lima - Peru

    • rachaelnelson's avatar
      rachaelnelson
      Frequent Visitor

      Thank you, Vvelarde.  Your measure gave me the same values I was receiving with my current calculated column but it got me thinking and I was able to solve using the following:

      cost/ton = CALCULATE(SUM(Table1[COST])/SUM(Table1[Tons]))

      • Vvelarde's avatar
        Vvelarde
        Community Champion

        rachaelnelson

         

        Yeah, sorry i had a bad read of your problem.

         

        I thought you need 226.83 instead of  232.85.

         

        Regards

         

        Victor

        Lima - Peru