Forum Discussion

joeguan's avatar
joeguan
Regular Visitor
9 years ago
Solved

Weighted AVG Aggregation

Hi,

I got a problem when creating a calculated member in PowerBI.

 

Here is the sample data:

CategoryProductSoldTotal
111234444
1200
13366
2412
2555
261012
379992000
385050
391222

I want to have a Sold Rate as a calculated column.

If I create a calculated column in Excel pivot table, it would be:  IF(Sold = 0 , 0 , Sold/Total)

It works perfect as below:

  Values  
CategoryProductSum of SoldSum of TotalSum of Sold Rate
1112344442.8%
 2000.0%
 33664.5%
1 Total 12645102.8%
241250.0%
 555100.0%
 6101283.3%
2 Total 161984.2%
37999200050.0%
 85050100.0%
 9122254.5%
3 Total 1061207251.2%
Grand Total 1203660118.2%

 

However, when using the same calculation method in PowerBI Devide(Sheet1[Sold],Sheet1[Total],0), it doesn't show the same number especially after aggregation.

It show 49% in the grand total by averaging each Sold Rate item...  That's not reasonable...

 

If I write Devide(sum(Sheet1[Sold]),sum(Sheet1[Total],0)   , then every single row of Sold Rate shows 18.2%.

 

I just want it to be exactly the same as the data showed up in Excel pivot table. Any suggestions?

 

 

  • Hi joeguan,

     

    In your scenario, please create a measure instead of a calculated column like below to calculate rate:

     

    Rate = DIVIDE(SUM(Sheet3[Sold]), SUM(Sheet3[Total]),0)

     

    Then create a matrix visual, place Category and Product in Rows, Sold, Total and Rate in Values.

     

     

    Best Regards,
    Qiuyun Yu

4 Replies

  • v-qiuyu-msft's avatar
    v-qiuyu-msft
    Community Support

    Hi joeguan,

     

    In your scenario, please create a measure instead of a calculated column like below to calculate rate:

     

    Rate = DIVIDE(SUM(Sheet3[Sold]), SUM(Sheet3[Total]),0)

     

    Then create a matrix visual, place Category and Product in Rows, Sold, Total and Rate in Values.

     

     

    Best Regards,
    Qiuyun Yu

    • joeguan's avatar
      joeguan
      Regular Visitor
      Hey Qiuyun, As I mentioned, if I use your formula, every single row shows 18.9%(the grand total number). I can't make a filter on category column though. Because it is always 18.9%...
    • joeguan's avatar
      joeguan
      Regular Visitor
      Ahhh, I got you. Create a measure instead of a column. Thanks so much!
      • v-qiuyu-msft's avatar
        v-qiuyu-msft
        Community Support

        Hi joeguan,

         

        It seems that my solution works in your scenario. If that is a case, would you please mark a proper reply as an answer so that we can close the thread? :smileyhappy:

         

        Best Regards,
        Qiuyun Yu